Facebook OAuthError - 无法将公开帖子发布到用户的提要

标签 facebook error-handling permissions facebook-oauth

我希望能够发布到用户墙上,(他编辑的消息)。但是,如果用户不允许代表他发帖,那么我会收到以下错误:

(#1) An error occured while creating the share|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();
}

编辑:
我发现当我再次允许权限时(通过收到错误消息后的链接),只有“所有人”/公众会产生错误,而只有我和 friend 不会。

更新(@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));

它将访问 token 发送到第三个页面(更新中的代码:“更新(@Axel Amthor):”)。

最佳答案

缺少范围参数,例如(来自我的代码):

$OAuth_request = _formatOAuthReq($OAuth, "read_insights,ads_management,publish_actions,manage_pages,publish_stream,read_stream,offline_access", $state);

....

function _formatOAuthReq($OAuthParams, $scope, $state)
{
    $uri = $OAuthParams['oauth_uri'];
    $uri .= "?client_id=" . $OAuthParams['client_id'];
    $uri .= "&redirect_uri=" . $OAuthParams['redirect_uri'];
    $uri .= "&scope=" . $scope;
    $uri .= "&response_type=code";
    $uri .= "&approval_prompt=force&access_type=offline";

为了在用户个人资料上发布某些内容,请考虑以下权限:
  • 创建事件
  • create_note
  • 照片_上传
  • 发布流
  • 读取流
  • 状态更新
  • 视频上传
  • 电子邮件
  • 发布操作

  • 根据 /[acctid]/feed您将在 [acctid] 标识的用户墙上发布“注释”。实际上,这是使用 OAuth 对话框中给出的访问 token “登录”的用户。我刚刚在这里查看了我们的代码,我们正在这样做
    /me/feed
    这就像一个魅力。实际上,不是您向“外国用户”发帖,而是用户本人,通过授予您的应用代表他/她这样做的权限,将您的应用发布到他/她自己的墙上。很复杂,我知道。

    关于Facebook OAuthError - 无法将公开帖子发布到用户的提要,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16692614/

    相关文章:

    c# - Facebook 与 dot net 的集成

    android - 登录错误 : There is an error in logging you into this application. 请稍后再试

    iphone - 使用 facebook/twitter 帐户登录

    error-handling - 在第 23 行安装 laravel 5 错误 composer.phar

    facebook - React Native `npm start` 出现 watchman 错误

    android - 通过接收 Intent 强制关闭错误

    haskell - 透明的错误处理

    java - 我希望我的服务在不提升的情况下运行,但作为恰好是管理员的用户(Windows/UAC)

    php - Cron 作业和文件夹权限 - 权限被拒绝

    ruby-on-rails - log/production.log 文件存在但为空