【问题标题】:Facebook API - Unsupported get request for page/post insightsFacebook API - 不支持获取页面/帖子见解的请求
【发布时间】:2015-10-20 13:17:49
【问题描述】:

我知道有很多关于 Facebook 的 SDK 和 API 以及这个特定错误响应的问题,但似乎没有一个回答我的问题。

我运行了一个 Facebook 页面,直到几天前,我还在运行一些代码,用于收集我 Facebook 页面上每个帖子的 insights 数据。

这就是我正在做的:

define('FB_APP_ACCESS_TOKEN', 'omitted'); // Never expires, has permission to read insight data (and more)
define('FB_APP_ID', 'omitted'); // ID of my Facebook App
define('FB_APP_SECRET', 'omitted'); // Secret for App
define('FB_ACCOUNT_ID', 'omitted'); // Facebook ID of my page
define('FB_REQUEST', 'insights/post_impressions_unique,post_consumptions_by_type,post_negative_feedback_by_type,post_consumptions,post_story_adds_by_action_type');

// .. Require Facebook SDK (Using composer)
// .. Other processing


// Initialise the Facebook SDK with our credentials and permanent access token.
$fb = new Facebook\Facebook([
    'app_id' => FB_APP_ID,
    'app_secret' => FB_APP_SECRET,
    'default_graph_version' => 'v2.2'
]);
$fb->setDefaultAccessToken(FB_APP_ACCESS_TOKEN);


// .. Grab some posts from my database
foreach ($posts as $post) {
    $postId = $post['id'];
    $request = FB_ACCOUNT_ID . '_' . $postId . '/' . FB_REQUEST;
    // Request will now contain something like...
    // <PAGE_ID>_<POST_ID>/insights/post_impressions_unique,post_consumptions_by_type,post_negative_feedback_by_type,post_consumptions,post_story_adds_by_action_type

    try {
        $fb->get($response); // This line fails and throw exception

        // .. Rest of my processing
    } catch (Facebook\Exceptions\FacebookSDKException $e) {
        die("\nEXCEPTION: {$e->getMessage()}\n{$e->getTraceAsString()}");
    }
}

上述代码运行良好,直到几天前我注意到我的统计数据没有起作用。经过一些调查并使用 Graph API Explorer 玩耍后,我发现我得到了以下输出:

例外:不支持的获取请求。请阅读 https://developers.facebook.com/docs/graph-api 的 Graph API 文档

并使用 Graph API Explorer:

{
  "error": {
    "message": "Unsupported get request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api",
    "type": "GraphMethodException",
    "code": 100,
    "fbtrace_id": "XXXXXXX"
  }
}

无论我尝试了什么,我似乎都无法再次获得页面上单个帖子的见解。我尝试过使用 Graph API Explorer,尝试了多种组合,但似乎无法获得任何回报。我什至尝试生成具有正确权限的新令牌无济于事。我尝试过的一些组合:

  • &lt;POST_ID&gt;/insights - (#12) singular statuses API is deprecated for versions v2.4 and higher
  • &lt;PAGE_ID&gt;/insights - 显示页面的所有见解,没有关于每个特定帖子的信息

有人知道我哪里出错了吗?

干杯

【问题讨论】:

  • 是的,我知道,但我始终确保我包含它。我已通过 SDK 包含在内,并确保将其也包含在 Graph API Explorer 中

标签: php facebook facebook-graph-api


【解决方案1】:

除了在每个请求中始终拥有正确的访问令牌之外,

处的文档

包含提示:

/{post-id}/insights(仅限页面帖子)* *注意:Graph API 对象 {post-id} 需要以 API 调用返回的相同格式指定以获取页面帖子列表 - 不要尝试拆分或合并其他 ID 组成一个帖子 ID

基线:尝试只使用

$request = $postId . '/' . FB_REQUEST;

而不是

$request = FB_ACCOUNT_ID . '_' . $postId . '/' . FB_REQUEST;

【讨论】:

  • 感谢您的回答。我已经尝试了您的建议,并在我的问题的第一个项目符号中提到了这一点。当我尝试 &lt;POST_ID&gt;/insights 时,我收到了带有消息 (#12) singular statuses API is deprecated for versions v2.4 and higher 的 OAuthException
  • 根据 v2.5 文档,这应该可以工作。我怎么知道&lt;POST_ID&gt; 对应于$postId。代码中没有。
  • 尝试了我页面的一个帖子,并且没有返回错误消息
  • 这很奇怪。我什至尝试在 Graph API Explorer 中运行 &lt;PAGE_ID&gt;/posts,单击随机帖子 ID(显示该帖子的详细信息),然后简单地将 /insights 附加到请求中。然而,这会显示一个不同的错误:An unknown error has occurred.
  • 这正是我所做的。您使用的是 v2.5 吗?访问令牌是否包含read_insights 权限?
猜你喜欢
  • 2015-06-13
  • 2016-04-26
  • 1970-01-01
  • 1970-01-01
  • 2012-11-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多