Facebook多次访问令牌批量请求

时间:2013-07-05 05:57:27

标签: php python facebook facebook-graph-api batch-processing

我想制作一个包含2个不同访问令牌的批处理请求。我研究并发现还需要一个后备访问令牌。我已将其中一个访问令牌作为后备访问令牌。所以,假设我有2个访问权限T1和T2,我已将T1作为后备访问令牌,然后我无法获取T2的数据,反之亦然。

以下是我用于执行批量请求的两个函数

batch_data = []
def addToBatchRequest():

username = some user name
access_token = token1
fql_query='SELECT%20username,name,%20mutual_friend_count%20FROM%20user%20WHERE%20uid%20IN(SELECT%20uid2%20FROM%20friend%20WHERE%20uid1%20in%20(SELECT%20uid%20FROM%20user%20WHERE%20username%20=%20"'+username+'"%20))order%20by%20mutual_friend_count%20DESC%20limit%203%20'
batch_data.append({
                  'method' : "GET",
                  'relative_url' :  "/fql?q="+fql_query+'&access_token='+access_token,
                  'access_token': access_token,
                  })
username = some user name
access_token = token2
fql_query='SELECT%20username,name,%20mutual_friend_count%20FROM%20user%20WHERE%20uid%20IN(SELECT%20uid2%20FROM%20friend%20WHERE%20uid1%20in%20(SELECT%20uid%20FROM%20user%20WHERE%20username%20=%20"'+username+'"%20))order%20by%20mutual_friend_count%20DESC%20limit%203%20'
batch_data.append({
                  'method' : "GET",
                  'relative_url' :  "/fql?q="+fql_query+'&access_token='+access_token,
                  'access_token': access_token,
                  })

def batch_call(access_t):
#if access_t is token1 then I am not able to get data for token2 and vice-versa
end_point = 'https://graph.facebook.com'
data = urllib.urlencode({'access_token': access_t, 'batch': json.dumps(batch_data) }) 
url = urllib2.urlopen(end_point, data)
response = url.read()
user_results = json.loads(response)
for user in user_results :
    user_body = json.loads(user['body'])
    print user_body['data'][0]['username']
url.close()

1 个答案:

答案 0 :(得分:0)

来到这里问同样的问题,并在这里找到答案:facebook batch request for multiple users

访问令牌位于网址中,而不是任何理智的人可能期望的批处理包中的单独条目。