【发布时间】:2013-05-22 13:06:56
【问题描述】:
我希望能够发布到用户墙(他编辑的消息)。但是如果用户不允许代表他发帖,那么我会收到以下错误:
(#1) 创建共享时出错|OAuthException
然后我读到我可以通过再次将他发送到我的登录 url 来再次请求许可,但即使在允许它之后它也会发送相同的错误。
代码:
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));
它将访问令牌发送到第三个页面,(更新中的代码:“更新(@Axel Amthor):”)。
【问题讨论】:
-
你能把代码粘贴到
$facebook被实例化和初始化的地方吗? -
@AxelAmthor 我已经更新了代码。
-
您能否验证此
$user_info = $facebook -> api('/me');是否有效? -
@AxelAmthor,是的,它返回一个填充了我的用户正确数据的数组。
-
我缺少的是某处的
scope参数,要求授予publish_stream、status_update或publish_action的权限-您想做什么?目前,我认为根本没有设置任何权限。
标签: facebook error-handling permissions facebook-oauth