我想发出一个包含 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()