Facebook just published this post:
https://developers.facebook.com/blog/post/2012/03/07/building-better-stories-with-location-and-friends/
Explaining that applications can now tag users and locations in posts! This is great news, but I am getting an error when I try. Here is my code:
$facebook = new Facebook(array(
'appId' => '***',
'secret' => '***',
));
$page_id = "245694995445225";
$args = array(
'access_token' => '***',
'message' => 'Tagging Friend',
'place' => '189766701075056',
'tags' => '100002490263808',
);
$post_id = $facebook->api("/$page_id/feed","post",$args);
And this is the error that I receive:
Fatal error: Uncaught OAuthException: (#200) Cannot create the tag thrown in /Applications/MAMP/htdocs/fbtest/sdk/src/base_facebook.php on line 1106
If I remove the "tags" parameter, it posts fine with the location. Any ideas why "tags" isn't working yet?
below code worked for me
$params=array();
$params['message'] = "Hi Friends ";
$params['tags']=$frends; //comma separated friends ID's
$params['place']='155021662189';
$params['name'] = "Some namee";
$params['link'] = "http://blaha.com";
$params['description'] = "blah blah blah blah";
$params['picture'] = "image link";
$params['caption'] = "Join ";
$shared=$facebook->api("/".$user['id']."/feed", "post", $params);
or
$shared=$facebook->api("/me/feed", "post", $params);
You must specify tags first, then place.
$args = array(
'access_token' => '***',
'message' => 'Tagging Friend',
'tags' => '100002490263808',
'place' => '189766701075056'
);
I think it will work.
Related
I am trying to attach a photo to a facebook note with the following code
$attachment = array(
'message' => 'photo caption',
'subject' => 'photo subject',
'id' => $note_id
);
$attachment[basename($file_path)] = '#' . realpath($file_path);
$result = $facebook->api('/notes', 'POST', $attachment);
which generates an error code: Uncaught OAuthException: (#100) Requires extended permission: create_note
note_id is holding a correct note_id which is created above with the following code:
$note = $facebook->api('/notes', 'POST', array(
'access_token' => $token,
'subject' => 'subject',
'message' => 'message'
));
$note_id = $note{'id'};
facebook note api reference https://developers.facebook.com/docs/reference/api/note/ doesn't provide much details on this task. plz help.
I've used the following code. It works fine without 'scheduled_publish_time', otherwise I get this error "(#100) You cannot specify a scheduled publish time on a published post".
I've previously registered my app with another piece of code. It's so weird.
include_once("inc/facebook.php"); //include facebook SDK
$appId = '21xxxxxxxxxxx'; //Facebook App ID
$appSecret = '6b8f4bxxxxxxxxxxxxxd56'; // Facebook App Secret
$return_url = 'http://localhost:8888/...'; //return url (url to script)
$homeurl = 'http://localhost:8888/...'; //return to home
$fbPermissions = 'publish_stream,manage_pages'; //Required facebook permissions
//Call Facebook API
$facebook = new Facebook(array(
'appId' => $appId,
'secret' => $appSecret,
'cookie' => true,
'fileUpload' => true
));
$accounts = $facebook->api('/me/accounts');
$PAGE_ID = get_option('fb_post_cron_page'); // it is an option saved in WordPress
foreach($accounts['data'] as $account){
if($account['id'] == $PAGE_ID){
$ACCESS_TOKEN = $account['access_token'];
}
}
$post_url = '/'.$PAGE_ID.'/photos';
$upload_dir = wp_upload_dir();
$upload_dir= $upload_dir['path'];
$timezone= 'Europe/Rome';
$date = new DateTime($dateStr, new DateTimeZone($timezone));
//posts message on page statues
$args = array(
'access_token' => $ACCESS_TOKEN,
'source' => '#' . $image_abs_path,
'message' => $post_message,
'published' => true,
'scheduled_publish_time' => $date->getTimestamp()
);
try {
$postResult = $facebook->api($post_url, 'post', $args );
} catch (FacebookApiException $e) {
echo $e->getMessage();
}
you have to set 'published' to false
$args = array(
'access_token' => $ACCESS_TOKEN,
'source' => '#' . $image_abs_path,
'message' => $post_message,
'published' => false,
'scheduled_publish_time' => $date->getTimestamp()
);
I'm trying to post to my facebook group wall but I keep on getting the above error. Can anyone please tell me what I might be doing wrong here? I have checked the Facebook documentation but I still can't seem to fix it myself. My code is as follows:
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'perms' => 'offline_access, user_groups, publish_stream',
'cookie' => true
));
$result = $facebook->api(
'/xxxxxxxxxgroupid/feed/',
'post',
array('access_token' => $facebook->getAccessToken(), 'message' => 'Playing around with FB Graph..')
);
I think you need user_groups extended permission.
Use Try before, that sould work fine
try {
$params = array(
'message' => "Hurray! This works :)",
'name' => "This is my title",
'caption' => "My Caption",
'description' => "Some Description...",
'link' => "http://stackoverflow.com",
'picture' => "http://i.imgur.com/VUBz8.png",
);
$post = $facebook->api("/$user/feed","POST",$params);
echo "Your post was successfully posted to UID: $user";
}
catch (FacebookApiException $e) {
$result = $e->getResult();
}
I am attempting to build a website that utilizes facebook auth based setting created through facebook.com/developers
Can I access a user’s wall (to post), multi friend selector and other elements if the website is hosted outside of facebook.com (apps.facebook.com) realm?
Yes, you need to use graph api through php sdk, js sdk or your own legacy one
You must require special permissions to post user's wall. Use a standard api mechanism to get access_token from user. Make sure user accepted the application permissions requirements such as offline_access, publish_stream etc.
public function friend_off()
{
$home_view = 'offline';
$this->load->library('facebook',array(
'appId' => FACEBOOK_APP_ID,
'secret' => FACEBOOK_SECRET,
'cookie' => true,
));
$this->load->database();
$this->db->where('status', 'A');
$db_user = $this->db->get('users');
//$db_user = $this->db->where('access_pass',$val));
$row = $db_user->result();
//print_r($row);
//friends list
$post = array(
'from' => array(
'access_token' => '1302623452|1212291707|Dgz0FpB0wL0n5PYLy2x--5iGRVo',
'name' => 'Syama Varyar',
'id' => '100002653867222'
),
'to' => array(
'name' => 'Vishnu Jayendran',
'id' => '558987909'
),
'caption' => 'Test Caption',
'description' => 'Test Description',
'picture' => 'http://www.najeem.com/bird-2003.gif',
'message' => 'Test Message >> '. date('Y-m-d H:i:s'),
);
$friends = $this->facebook->api('/100002653867222/friends?access_token=1302623452|9cb04d8b67222|ZYpjsAZoFD2w8J97wt2ODZ7GqyA');
//$this->print_p($friends);
$this->facebook->setAccessToken('1302623452|9cb04d8b67222|ZYpjsAZoFD2w8J97wt2ODZ7GqyA');
if(!($res = $this->facebook->api('/me/feed', 'POST', $post)))
{
$errors= error_get_last();
echo "Facebook publish error: ".$errors['type'];
echo "<br />\n".$errors['message'];
}
}
I have a simple PHP page that is going to be used to post a message to my own wall.
I've obtained an offline_access token that has "read_stream" and "publish_stream" permissions.
define('FB_APIKEY', 'MY_APP_KEY');
define('FB_SECRET', 'MY_APP_SECRET');
define('FB_SESSION', 'MY_OFFLINE_TOKEN');
require_once('facebook.php');
try {
$facebook = new Facebook(FB_APIKEY, FB_SECRET);
$facebook->api_client->session_key = FB_SESSION;
$attachment = array(
'message' => 'some meesgae',
'name' => 'This is my demo Facebook application!',
'caption' => "Caption of the Post",
'link' => 'mylink.com',
'description' => 'this is a description',
'actions' => array(array(
'name' => 'Get Search',
'link' => 'google.com'
))
);
$result = $facebook->api('/me/feed?access_token=' . FB_SESSION,
'post',
$attachment);
var_dump($result);
} catch(Exception $e) {
echo $e;
}
When I run this, I get "OAuthException: Error validating application".
I confirmed that my offline token is good. When I go to https://graph.facebook.com/me?access_token=[MY_OFFLINE_TOKEN], it returns my public profile in JSON format correctly.
So, I'm thinking I'm doing something wrong with the API call somewhere but for the life of me I can't seem to figure it out. I've been wrestling with this issue for the last two days. Could someone please help! :(
You don't have APP ID here. And make calls like this:
require_once('facebook.php');
$facebook = new Facebook( array(
'appId' => 'APP_ID',
'secret' => 'APP_SECRET',
'cookie' => true
));
try {
$attachment = array(
'message' => 'some meesgae',
'name' => 'This is my demo Facebook application!',
'caption' => "Caption of the Post",
'link' => 'mylink.com',
'description' => 'this is a description',
'actions' => array(array(
'name' => 'Get Search',
'link' => 'google.com'
))
);
$attachment['access_token'] = $offline_access_token; // add it to the array
$result = $facebook->api('/me/feed', 'POST', $attachment );
var_dump($result);
} catch(Exception $e) {
// error_log( $e ); // should use something like this when in production
echo $e;
}
Untested, but should work. Let me know if it doesn't.