我希望它并不复杂,但由于Facebook已经更改了很多API(关于权限等),我发现许多过时的信息对我没有帮助。 情况是:
问题:如何通过该应用向用户发布时间表?
到目前为止我的代码(发布到页面墙上)
require 'facebook.php';
$facebook = new Facebook(array(
'appId' => 'xxxxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxx',
));
$loginUrl = $facebook->getLoginUrl();
$user = $facebook->getUser();
$page_id = 'xxxxxxxxxxxxxxxxxxxx';
$page_info = $facebook->api("/$page_id?fields=access_token");
if( !empty($page_info['access_token']) ) {
$args = array(
'access_token' => $page_info['access_token'],
'message' => "Neuer Test!"
);
$post_id = $facebook->api("/$page_id/feed","post",$args);
} else {
$permissions = $facebook->api("/me/permissions");
if( !array_key_exists('publish_stream', $permissions['data'][0]) ||
!array_key_exists('manage_pages', $permissions['data'][0])) {
header( "Location: " . $facebook->getLoginUrl(array("scope" => "publish_stream, manage_pages")) );
}
}
这样可以正常工作,但该消息在喜欢该页面的用户的时间轴中不可用,只能在他们自己的流中。是否可以发布到他们的时间表?
答案 0 :(得分:0)
不知道你是否还需要帮助。但为了以防万一,这段代码适合我。它假设您有一个登录用户。它会发布到用户的时间表。这段代码没有得到我认为的许可,因为Facebook有平台TOS,你需要继续工作。试试这个:
require_once('libs/facebook.php');
// init new facebook class instance with app info (taken from the DB)
$facebook = new Facebook(array(
'appId' => 'your app id here',
'secret' => 'your app secret here'
));
$fb_user_id = $facebook->getUser();
$location = "". $facebook->getLoginUrl(array('scope' => 'publish_stream'));
if ($fb_user_id) {
try {
$fb_user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
$fb_user_id = NULL;
print '<script language="javascript" type="text/javascript"> top.location.href="'. $location .'"; </script>';
die();
}
} else {
print '<script language="javascript" type="text/javascript"> top.location.href="'. $location .'"; </script>';
die();
}
$ret_obj = $facebook->api('/me/feed', 'POST',
array(
'link' => 'www.google.com',
'message' => 'Google me!'
));