我已经在php mysql中创建了一个facebook应用程序,现在我想将更新从应用程序传递到用户墙,它不是像按钮,而是我想在用户墙上共享的活动。很像:
我设法连接到Facebook并从Facebook获得用户ID,如下所示:
$facebook = new Facebook(array(
'appId' => 'xxxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
));
// Get User ID
$user = $facebook->getUser();
if ($user) {
try {
// Get the user profile data you have 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>');
}
答案 0 :(得分:2)
您必须先获得publish_stream
extended permission。
然后,您可以使用Facebook Javascript SDK中的stream.Publish
方法,auto_publish
参数设置为true
,或查看图API文档的{publish'部分{{ 3}}也可用于实现此目的。
答案 1 :(得分:0)
下面的代码确实有效:即使你没有获得许可也会尝试获取它们
$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")) );
}