-1

I am using this code for logging in to my app. It works fine, but when I try to get the url for profile pic

pic = facebook.get("/me/picture?fields=url")

I get None in response.

TypeError: must be string or buffer, not None

If I try sending this GET request from facebook Graph API, with same access-token, I get the profile link.

enter image description here

I checked out the version message by printing out get("/me") request, I get

connection: keep-alive
etag: "2c59a2baef08156f18055c64eaa9d9822e35e8f1"
pragma: no-cache
cache-control: private, no-cache, no-store, must-revalidate
date: Fri, 23 Jun 2017 14:20:04 GMT
**facebook-api-version: v2.9**
access-control-allow-origin: *
content-type: text/javascript; charset=UTF-8

Which shows that version is automatically converting when i send request from flask-OAuth as well. Then what is it that I am missing ?

Anum Sheraz
  • 2,383
  • 1
  • 29
  • 54
  • As the documentation says, this endpoint returns a _redirect_ to the user’s profile picture on Facebook’s CDN by default; if you want JSON returned, you need to add the extra parameter it mentions. (Graph API Explorer handles that differently, and always shows JSON, even without the parameter.) – CBroe Jun 23 '17 at 14:43
  • where do I have to add extra parameters ? Can you point out to the document, where it is mentioned. I tried to search, but couldn't find. – Anum Sheraz Jun 23 '17 at 16:29
  • https://developers.facebook.com/docs/graph-api/reference/user/picture – CBroe Jun 23 '17 at 16:41
  • I just did it... was reading this article. and I put redirect=false in my query and finally got the response. But why down vote ? – Anum Sheraz Jun 23 '17 at 16:43

1 Answers1

0

As documented in the Graph API, "me/picture?" will return a 302 redirect to the picture image. To get access to the data about the picture, we need to include redirect=false in the end of query. So I get the url by;

pic = facebook.get('/me/picture?redirect=false').data
print 'picture:', pic['data']["url"]
Anum Sheraz
  • 2,383
  • 1
  • 29
  • 54