Torxed
Torxed

Reputation: 23490

Facebook Graph API - Get profile picture prior to authenticating

Ok so i've tried the following:

FB.api("/me", {fields: "picture"}, function(response){
    console.log(response);
});

And i'm trying to work around http://graph.facebook.com/USERNAME_OR_USERID/picture since obviously i don't know the users ID prior to authenticating. All i want is a "modern" feel within the website, so i'd like to present the user with his or her's profile picture on the "login" div presenting the facebook login button. Is this possible? I know that Facebook and their graph api prohibits most such features but i would hope that a public profile picture would be accessible through the graph API..

I've Googled around and all the solutions say "use the USERNAME in the URL and you're fine" but i'm not, so to clear out any doubts, is this possible?

Error message: An active access token must be used to query information about the current user.

Upvotes: 2

Views: 8821

Answers (2)

Viral Solani
Viral Solani

Reputation: 840

You can get everyone's Facebook profile picture without authentication.

You just call http://graph.facebook.com/USERNAME_OR_USERID/picture?type=large. This URL redirects you to image URL.

Type may be normal,small or large.

Upvotes: 3

Stéphane Bruckert
Stéphane Bruckert

Reputation: 22933

I also have questions for you:

  • How do you want to display the picture of someone without knowing who he/she is?
  • How can you guess which account the visitor will use to connect?

It looks like you want to know whose Facebook account was lastly connected on the browser of your visitor. Technically, you would want to read another site's cookies, which is 1) not allowed 2) impossible.

Several additional things you need to know:

  • http://graph.facebook.com/USERNAME_OR_USERID/picture is a public way to retrieve someone's photo. You don't need a token for that. What else do you need?
  • Using FB.API("/me", ...) from the JS SDK implies that "me" represents the connected user. It cannot just be used alone.

By the way, identical questions have already been answered and accepted:

Why would you hope the impossible?

Upvotes: 1

Related Questions