是否允许使用per-request access_tokens将查询批处理到FQL?它不起作用

时间:2012-04-25 16:20:56

标签: facebook-graph-api facebook-fql fql.multiquery facebook-batch-request

是否无法使用多个访问令牌使用'method / fql.query?query = ...'批量查询图表?

在过去的批处理中,我从来没有遇到过使用多个访问令牌查询非fql端点的麻烦,但是通过批量查询FQL调用,只有第一次调用返回数据,其余的返回一个空体。

我能做的唯一猜测就是它与access_token有关,但如果是这样的话,我有点不知道如何补救......

示例:

import json
from pyfaceb import *

user1_tk = '...' #valid token (tested)
user1_qry = '...' #valid query (tested unbatched)
user1_rqst = {'method': 'POST', 'relative_url': 'method/fql.query?query=' + user1_qry, 'access_token': user1_tk}

user2_tk = '...' #valid token (tested)
user2_qry = '...' #valid query (tested unbatched)
user2_rqst = {'method': 'POST', 'relative_url': 'method/fql.query?query=' + user2_qry, 'access_token': user2_tk}

batches = [user1_rqst, user2_rqst]

fbg = FBGraph(user1_tk) # use user1_tk as fallback access token (cuz you have to specify one)
data = fbg.get_batch(batches)

print data[0]['body'] #comes back with data, but
print data[1]['body'] #comes back as an empty array.

data [0] ['code']和data [1] ['code']都是HTTP 200响应。

如果我将后备访问令牌更改为user2_tk,则data [0] ['body']将作为空数组返回(反之亦然)。即使我为每个请求指定了access_tokens(per:https://developers.facebook.com/docs/reference/api/batch/#differentaccesstokens

1 个答案:

答案 0 :(得分:0)

想出来。 acccess_token需要在请求体中,因为它是POST:

...
user1_rqst = {
    'method': 'POST',
    'relative_url': 'method/fql.query?query=' + user1_qry,
    'body': 'access_token=' + user1_tk
}

...

user2_rqst = {
    'method': 'POST',
    'relative_url': 'method/fql.query?query=' + user2_qry,
    'body': 'access_token=' + user2_tk
}