get_user_info does not work with requests module properly
cringoleg opened this issue · 1 comments
cringoleg commented
def get_user_info(self, recipient_id, fields=None):
"""Getting information about the user
https://developers.facebook.com/docs/messenger-platform/user-profile
Input:
recipient_id: recipient id to send to
Output:
Response from API as <dict>
"""
params = {}
if fields is not None and isinstance(fields, (list, tuple)):
params['fields'] = ",".join(fields)
params.update(self.auth_args)
request_endpoint = '{0}/{1}'.format(self.graph_url, recipient_id)
response = requests.get(request_endpoint, params=params)
if response.status_code == 200:
return response.json()
return None
When passing params
in func get_user_info()
, module requests
interprets the string with passed parameters and changes all commas to comma escape character.
In the end, the URL part with passed parameters ['time_zone', 'first_name']
looks like this: fields=time_zone%2Cfirst_name
, but in messenger API it should look like this: fields=time_zone,first_name
cringoleg commented
Nevermind, it works good :)