I have made a facebook application in php mysql, now i want to pass updates from the application to the users wall, its not a like button but an activity that i want to share on user wall. much like:
xxx just had pizza for lunch, via logUrLunch App
i hv managed to connect to facebook and got user id from facebook as follows:
$facebook = new Facebook(array(
'appId' => 'xxxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
));
// Get User ID
$user = $facebook->getUser();
if ($user) {
try {
// Get the user profile data you ha开发者_StackOverflow社区ve permission to view
$user_profile = $facebook->api('/me');
$uid = $facebook->getUser();
session_start();
$_SESSION['userID'] = $uid;
//print_r($user_profile);
//echo "</pre>";
} catch (FacebookApiException $e) {
$user = null;
}
} else {
die('<script>top.location.href="'.$facebook->getLoginUrl().'";</script>');
}
You must first be granted the publish_stream
extended permission.
Then you can use the stream.Publish
method in the Facebook Javascript SDK with the auto_publish
parameter set to true
, or check out the 'publishing' section of the graph API docs here which can also be used to accomplish this.
below code surely works: even if you dont have permission it will try to get them
$facebook = new Facebook(array(
'appId' => 'xxxxxxxxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
));
$user = $facebook->getUser();
$user_profile = $facebook->api('/me');
if( array_key_exists('publish_stream', $permissions['data'][0]) ) {
// Permission is granted!
// Do the related task
//$post_id = $facebook->api('/me/feed', 'post', array('message'=>'Hello World!'));
$post_id = $facebook->api('/me/feed', 'post', $attachment);
} else {
// We don't have the permission
// Alert the user or ask for the permission!
echo "Click Below to Enter!";
header( "Location: " . $facebook->getLoginUrl(array("scope" => "publish_stream")) );
}
精彩评论