Facebook评论(最新)使用Facebook图形API和Python

时间:2015-02-04 04:57:19

标签: python facebook facebook-graph-api

我试图访问Facebook页面https://www.facebook.com/HRCMallOfAmerica/reviews(特别是最近一次)的评论标签下显示的数据。

import json
import oauth2
import urllib
import urllib2
import psycopg2


url_params = {}
url_params['client_id'] = 'xxxxxxxxxxxxxxxxx'
url_params['client_secret'] = 'xxxxxxxxxxxxxxxxxxxxxxxxx'
url_params['grant_type'] = 'client_credentials'
host = 'graph.facebook.com/oauth/access_token'
encoded_params = urllib.urlencode(url_params)
url = 'https://%s?%s'%(host,encoded_params)
try:
    response = urllib2.urlopen(url)
    access_token = response.read().split('access_token')[1][1:]
except:
    print "Unable to get / parse the URL %s"%(url)
print 'ACCESS_TOKEN %s'%(access_token)

我可以使用以下网址获取自己的Feed

url=https://graph.facebook.com/HRCMallOfAmerica/feed?access_token=xxxxxxxxx

从下面的问题中看到答案。

Facebook "Reviews" Tab Data -- Where is it stored in Graph API and how to access it?

我打电话给名为

的网址

http://graph.facebook.com/622086227888427/reviews

http://graph.facebook.com/622086227888427/reviews?limit=100000000&offset=0

但是两个网址都会抛出相同的错误,例如

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

提前致谢。

1 个答案:

答案 0 :(得分:1)

如果您是此页面的管理员,则可以使用图表API在评分'节点(更多信息:https://developers.facebook.com/docs/graph-api/reference/page/ratings/):

GET /v2.5/{page-id}?fields=ratings HTTP/1.1
Host: graph.facebook.com

你可以使用facebook-sdk使用python执行此操作。

如果您不是该页面的管理员,则无法使用图谱API获取该信息。