1

I want to make a batch request consisting of 2 different access token. I researched and found out that one need a fallback access token also. I have made one of the access token as fallback access token. So, suppose I have 2 access tokens T1 and T2 and I have made T1 as fallback access token then I am not able to get data of T2 and vice versa.

Below are the two functions that I am using for doing batch request

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()
Aacini
  • 65,180
  • 12
  • 72
  • 108
Utkarsh Srivastav
  • 3,105
  • 7
  • 34
  • 53

1 Answers1

0

Came here to ask the same question, and found the answer here: facebook batch request for multiple users

The access token goes in the url instead of being a separate entry in the batch package as any sane person might expect.

Community
  • 1
  • 1
mutatron
  • 563
  • 3
  • 7
  • 19