[英]Facebook page - post to users wall(after the user has liked the page)
我希望它不是那么复杂,但是由于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")) );
}
}
一切正常,但是在喜欢该页面的用户的时间轴中,仅在他们自己的流中,该消息不可用。 可以发布到他们的时间表吗?
不知道您是否仍然需要帮助。 但以防万一,此代码对我有用。 假定您有一个登录用户。 并发布到用户的时间轴。 此代码未获得我认为的许可,因为Facebook具有Platform 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!'
));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.