我希望能够发布到用户墙上,(他编辑的消息)。但是,如果用户不允许代表他发帖,那么我会收到以下错误:
(#1) 创建共享时发生错误|OAuthException
然后我读到我可以通过再次将他发送到我的登录网址来再次请求许可,但即使在允许它之后它也会发送相同的错误。
代码:
try{...
$ret_obj = $facebook -> api('/' . $user_id . '/feed', 'POST', array('name' => $title, 'link' => $redirect_url, 'caption' => $ptnr_fb_caption, 'icon' => 'http://...logo-small.png', 'picture' => $ptnr_fb_img, 'message' => $desc, 'privacy' => $arrPriv));
} catch(FacebookApiException $e) {
echo '<div id="text">Error :</div><br /><p style="width: 365px;margin: 0 auto;">Problem authenticating via Facebook, please allow us to share on your behalf.</p>';
echo '<center><a href="https://www.facebook.com/dialog/oauth?client_id=<my_id>&redirect_uri=http://<mysite>/getFacebookData.php&display=popup&scope=email,publish_stream&type=web_server">Allow here</a><center>';
//Send email to admin
$subject = "ERROR Facebook";
$body = "user email:" . $user_email . '| error:' . $e -> getMessage().'|'.$e->getType();
}
编辑: 我发现当我再次允许权限时(通过收到错误消息后的链接),只有“所有人”/公众会产生错误,而只有我和朋友不会。
更新(@Axel Amthor):
$facebook = new Facebook( array('appId' => 'app_id', 'secret' => 'removed', ));
//We got after the authentication request
$access_token = $_POST['access_token'];
$facebook -> setAccessToken($access_token);
try {
$user_info = $facebook -> api('/me');
$user_id = $user_info['id'];
} catch (FacebookApiException $e) {
//return 0;
}
更新 2: 范围相关代码:
$red_url = 'https://www.facebook.com/dialog/oauth?client_id=my_id&redirect_uri=http://mysite/facebook/getFacebookData.php&display=popup&scope=email,publish_stream&type=web_server';
它重定向到 getFacebookData.php:
$access_token = '';
$token_url = "https://graph.facebook.com/oauth/access_token?client_id=my_id&redirect_uri=http://mysite/facebook/getFacebookData.php&client_secret=secret&code=" . $_GET['code'];
$access_token = file_get_contents($token_url);
$access_token = substr($access_token, 13, strlen($access_token) - (13 + 16));
It sends that access token to the tird page, (code in update: "Update (@Axel Amthor):").