Facebook graph api 我想从我的网站在我的粉丝页面上发布
我已经在facebook上创建了一个应用程序,在php sdk之间,我可以在我的个人资料上发布我网站的文章 现在,我想把我的文章发布在我的粉丝页面上,而不是我的文件中。我怎么能做到 这是我使用的代码,与facebook开发者中的示例差别不大:Facebook graph api 我想从我的网站在我的粉丝页面上发布,facebook-graph-api,fan-page,Facebook Graph Api,Fan Page,我已经在facebook上创建了一个应用程序,在php sdk之间,我可以在我的个人资料上发布我网站的文章 现在,我想把我的文章发布在我的粉丝页面上,而不是我的文件中。我怎么能做到 这是我使用的代码,与facebook开发者中的示例差别不大: // Remember to copy files from the SDK's src/ directory to a // directory in your application on the server, such as php-s
// Remember to copy files from the SDK's src/ directory to a
// directory in your application on the server, such as php-sdk/
require_once('facebook.php');
$config = array(
'appId' => 'xxxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxx',
);
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
?>
<?
if($user_id) {
// We have a user ID, so probably a logged in user.
// If not, we'll get an exception, which we handle below.
try {
$access_token = $facebook->getAccessToken();
$page_id='xxxxxxxxxxxxxx';
$ret_obj = $facebook->api('/me/feed', 'POST',
array(
'link' => $link,
'message' => $titolo,
'picture' => 'http://xxxxxxxxxxxxxxxxxx',
'name' => 'Ecosport',
'access_token' => $access_token
));
echo '<pre>Post ID: ' . $ret_obj['id'] . '</pre>';
} catch(FacebookApiException $e) {
// If the user is logged out, you can have a
// user ID even though the access token is invalid.
// In this case, we'll get an exception, so we'll
// just ask the user to login again here.
$login_url = $facebook->getLoginUrl( array(
'scope' => 'publish_stream'
));
header("location:$login_url");
error_log($e->getType());
error_log($e->getMessage());
}
// Give the user a logout link
$id_articolo=$_GET['id_articolo'];
header("location:xxxxxxxxxx");
/*echo '<br /><a href="' . $facebook->getLogoutUrl() . '">logout</a>';*/
} else {
// No user, so print a link for the user to login
// To post to a user's wall, we need publish_stream permission
// We'll use the current URL as the redirect_uri, so we don't
// need to specify it here.
$login_url = $facebook->getLoginUrl( array( 'scope' => 'publish_stream' ) );
header("location:$login_url");
/*echo 'Please <a href="' . $login_url . '">login.</a>';*/
}
?>
//记住将文件从SDK的src/目录复制到
//服务器上应用程序中的目录,例如php sdk/
需要_一次('facebook.php');
$config=array(
“appId”=>“XXXXXXXXXXXX”,
“机密”=>“XXXXXXXXXXXXXXXXXX”,
);
$facebook=newfacebook($config);
$user_id=$facebook->getUser();
?>
您需要请求管理页面
和发布流
权限。然后调用/me/accounts以获取用户管理的帐户列表(也称为页面)。该帐户列表中的每个帐户都将有一个与其关联的访问令牌。该访问令牌是特殊的,需要用于新建facebook api实例。一旦您这样做,发布到页面墙与发布到用户墙(即/me/feed)相同。请参阅DMCS的页面登录部分,该部分以用户身份发布到风扇页面。你知道如何将其作为fan页面发布到fan页面吗?不,我上面的解释不是作为用户发布到流,而是作为页面发布,因为它使用页面的访问令牌。