Can't get “count” in “likes” and “comments” fields using my own registered app's access_token

亡梦爱人 提交于 2019-12-10 09:19:22

问题


Main Question:

When I sent a GET request to retrieve data of someID/POSTS, like https://graph.facebook.com/microsoft/posts?fields=comments,likes&limit=1&access_token=, cannot get the "count" in "likes" and "comments" fields using the access token generated by my own facebook registered app, but can get the expected data if using the access token from Facebook Sample apps, e.g. "HelloFacebookSample".

This issue occurs on both Android and FB Graph API Exploer. Also in oder to troubleshoot the possible causes, I used the exactly same codes as FB sample under my registered app_id, but the same problem came out again. So the only possible explanation I can think of is some strange things with FB app_id, not the permission scopes or different users(I've tested using two users).

Here is, the Reponses from GET request of https://graph.facebook.com/microsoft/posts?fields=likes&limit=1&access_token=:

1.Using access_token generated by my app_id:

{
  "data": [
    {
       "id": "20528438720_10151574758413721", 
       "created_time": "2013-07-18T18:41:51+0000", 
       "likes": {
          "data": [
            {
               "id": "701134683", 
               "name": "Someone's name"
            }, 
            {
               "id": "113770258795376", 
               "name": "Someone's name"
            }
            /****and so on****/
        ], 
        "paging": {
         "cursors": {
           "after": "MTAwMDAwNjkxNDMxMTcz", 
           "before": "NzAxMTM0Njgz"
         }, 
         "next": "https://graph.facebook.com/20528438720_10151574758413721/likes?limit=25&after=MTAwMDAwNjkxNDMxMTcz"
       }
     }
   }
  ], 
  "paging": {
    "previous": "https://graph.facebook.com/20528438720/posts?fields=likes&limit=1&since=1374172911", 
    "next": "https://graph.facebook.com/20528438720/posts?fields=likes&limit=1&until=1374172910"
  }
}

2.Using access_token generated by FB's sample app_id(here it can get "count" of likes):

{
  "data": [
      {
        "likes": {
          "data": [
          {
                "name": "Someone's name", 
              "id": "100003531173993"
            }, 
            {
              "name": "Someone's name", 
              "id": "100002299390558"
            }, 
            {
              "name": "Someone's name", 
              "id": "1038509978"
            }, 
            {
              "name": "Someone's name", 
              "id": "1615491698"
            }
          ], 
        "count": 1071
      }, 
      "id": "20528438720_10151574758413721", 
      "created_time": "2013-07-18T18:41:51+0000"
    }
  ], 
  "paging": {
    "previous": "https://graph.facebook.com/20528438720/posts?fields=likes&limit=1&since=1374172911", 
    "next": "https://graph.facebook.com/20528438720/posts?fields=likes&limit=1&until=1374172910"
  }
}

It really confused me for days, and I've done lots of searches, but cannot find any useful or related info perhaps due to my English:P. Did anyone else face the similar problems?

Thank you for reading.

Any help or alternative solution appreciated! (here, I just want to display the number of likes in my app)


回答1:


Just found the solution myself, it is all due to the FB's migration for the October 2013 Breaking Changes. They change the POST_ID/likes format, but probably as the migration has not been completed yet, so there are some inconsistencies. The following is an official statement that I got from the Facebook Developer Alert.

POST_ID/likes format will change. Apps will be able to retrieve all likes on a post (rather than the first 4 as it is today) through paging. As a result of the functionality update, the like count will be moved to the summary field.

So now if you cannot see “count” in “likes” or “comments” field, just follow the steps below:

  1. Send a GET request to, let's say https://graph.facebook.com/microsoft/posts?fields=likes&limit=1&access_token= and then you get the POST_ID = "id"
  2. a new GET request to https://graph.facebook.com/POST_ID/likes?summary=true&access_token=, then you will find the "total_count" of "likes" in "summary" field.

Hope this helps!



来源:https://stackoverflow.com/questions/17733360/cant-get-count-in-likes-and-comments-fields-using-my-own-registered-apps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!