首次通过facebook连接登录我网站的用户将重定向到php脚本,该脚本应邀请他们加入我的社团facebook群组。
<?php
require_once "facebook_sdk/src/facebook.php";
$app_id = 'xxxxxxx';
$app_secret = 'xxxxxxx';
// Init facebook api.
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
// Get the url to redirect for login to facebook
$login_url = $facebook->getLoginUrl(
array('scope' => 'manage_pages')
);
// If not authenticated, redirect to the facebook login dialog.
// The $login_url will take care of redirecting back to us
// after successful login.
if (! $facebook->getUser()) {
echo <<< EOT
<script type="text/javascript">
top.location.href = "$login_url";
</script>;
EOT;
exit;
}
$token=$facebook->getAccessToken();
echo $token . "</br>";
$user=$facebook->getUser();
$page = "/45277909073/members/" . $user . "/";
echo $page;
$facebook->api($page, "post",array('access_token='=>$token));
?>
此代码输出以下
173863136082149 | 9f42756f3760ff697b3c4e809bfe48f7
/ 45277909073 /构件/ 987654321 /
致命错误:未捕获OAuthException:请求此资源需要用户访问令牌。在第1238行的/home/somewhere/public_html/fb/facebook_sdk/src/base_facebook.php中引用
我将此基于邀请用户部分下的doku https://developers.facebook.com/docs/reference/api/group/
答案 0 :(得分:1)
in
'access_token=' => $token
应该是
'access_token' => $token