【问题标题】:Facebook Page Likes and its information getting API returned empty dataFacebook Page Likes 及其信息获取 API 返回空数据
【发布时间】:2018-02-27 11:28:46
【问题描述】:

我在这个网站上看到过类似的帖子,但没有一个能解决我的问题,api 版本已经改变,一些端点已被弃用。

当我使用时,即使是 Graph API Explorer,我也会收到包含空数据的响应。

// Instantiating the Facebook class
$this->api = new Facebook([
    'app_id' => $ apiId,
    'app_secret' => $ apiSecret,
    'default_graph_version' => 'v2.11',
    ]);
....
// Creating the authentication link
$helper = $this->api->getRedirectLoginHelper();
    $permissions = ['manage_pages', 'publish_pages', 'read_insights']; // Optional permissions
    $loginUrl = $helper->getLoginUrl ('http://dev2.example.co/smms/index.php?id=16', $permissions);
...
// Getting the total of likes of the page (the endpoint 'fan_count' does not work for this version)
$this->api->get('/'.$this->id_profile.' / likes', $this->getAccessTokenAttribute())

结果为空,访问令牌在所有情况下都是正确的。

另一方面,当我只调用页面上的信息时,它只传递页面名称和id的数据

protected 'decodedBody' =>
    array (size = 2)
      'name' => string 'Test Page' (length = 9)
      'id' => string '1989831694572991' (length = 16)

如果您能指导我获取页面上的所有信息,我将不胜感激。我不知道是否缺少任何页面级别的权限来实现它。

我正在使用 TYPO3 7.6 和 PHP 5.6。

【问题讨论】:

  • 不,/likes 不是页面粉丝数,它是您页面喜欢的其他页面的列表。 fan_count 正确的字段,它在 API v2.11 中运行良好,developers.facebook.com/tools/… 很容易证明。

标签: php facebook facebook-graph-api typo3


【解决方案1】:

将喜欢更改为 fan_count

$this->api->get('/'.$this->id_profile.'?fields=fan_count', $this->getAccessTokenAttribute());

我认为fans_count 在 v2.11 中工作。如果它不适合您,请分享更多代码以供检查

【讨论】:

  • 使用$this->api->get('/'.$this->id_profile.' / fan_count', $this->getAccessTokenAttribute()) 我得到这个错误Unknown path components: /fan_count exception code:2500 file:/typo3conf/ext/smms/Resources/Private/Libs/facebook/src/Facebook/Exceptions/FacebookResponseException.php line:131 但使用你在屏幕截图中显示的$this->api->get('/'.$this->id_profile.'?fields=fan_count', $this->getAccessTokenAttribute()); 有效。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多