Morten Bergfall
Morten Bergfall

Reputation: 2316

Problem obtaing profile pictures from Facebook Graph API

Have gotten the foundation in place, but now, finding myself wanting to play around with my
application's user's profile pictures; I'm stumped....and have been for quite some hours...

Firstly, my oauth_token / access_token is obtained, using the official (though Alpha ;-)
Facebook C# SDK and only utilize the Graph API.

FBapi.Get("/" + friend.Dictionary["id"].String + "/picture");

leads to an exception due to not returning a JSONObject, and

using the complete http://graph.facebook.com/me/picture is forwarded/translated to the image's URL.

Trying a more direct approach didn't pan out either :

WebClient wcImg = new WebClient();

wcImg.DownloadFile("/" + friend.Dictionary["id"].String + "/picture", "name_blame.jpg");

Some details are lacking in my question; I beg your pardon, am very tired and will edit later if uproar commences.

Ideas?


Addendum : Boy, afflicted by code blindness I was indeed! However, your sensibility gave me what I needed (Zynga, tremble in my canvas ;-).

For sake of curiosity...it appears there's no JSON template(pardon my lack of lingo) available for profile pictures? Then how do one go about obtaining a fleshed out, Graph API Photo of that profile picture (if available)?

Upvotes: 2

Views: 5553

Answers (3)

serg
serg

Reputation: 111265

The picture in Graph API is a bit special animal. It doesn't return json, it directly forwards to the image. It was made so that you can use this url right in html:

<img src="http://graph.facebook.com/<UID>/picture"> - displays avatar

Now if you need to know actual picture URL it redirects to there are 2 options:

  1. Read redirect headers from that graph URL.
  2. Use FQL:

    select pic_square from user where uid=12345
    

There is alot of other info that can be extracted about a user using FQL (including pictures in other sizes).

Upvotes: 4

darki699
darki699

Reputation: 441

You can get ALL friends' profile pictures (direct Links to the photos), in a single GET request:

https://graph.facebook.com/me/friends?access_token=[oauth_token]&fields=name,id,picture

Then use Json to Decode the string.. and that's all...

NJoy ^_^

Upvotes: 1

Beiru
Beiru

Reputation: 312

Also, if You want to show big profile photo, use this:

http://graph.facebook.com/<UID>/picture?type=large

Upvotes: 3

Related Questions