ardavis
ardavis

Reputation: 9895

Determine if user's Facebook image is the default with Omniauth

I am getting the user's facebook image with:

https://graph.facebook.com/#{omniauth.uid}/picture?type=large

But how can I check if that is the Facebook Default image? If it is, I have my own image I would like to use.

I am using Ruby on Rails and Omniauth. So if Omniauth provides anything that would help this situation, let me know.

UPDATE

When I go to my own page using the link above, but my User ID, if I have no profile image set, I get redirected to this file.

https://fbcdn-profile-a.akamaihd.net/static-ak/rsrc.php/v2/yL/r/HsTZSDw4avx.gif

I had a friend also check, and he got the same page.

So I could "temporarily" check against that filename, but clearly that would be a horrible practice. If Facebook changes their default image, everything fails. Any flag to tell me if the user has an image set or not?

Upvotes: 1

Views: 579

Answers (1)

rubenrails
rubenrails

Reputation: 176

Use the is_silhouette boolean. From the documentation:

You can add a redirect=false to the HTTP request to get the location instead of the actual data. This call:

<img src="https://graph.facebook.com/shaverm/picture?redirect=false"/>

will return JSON-encoded data describing the location of the picture. url is the location of the image and the is_silhouette boolean indicates whether or not the object has set a picture.

{
    "data": {
        "url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash4/372183_100002526091955_998385602_q.jpg",
        "is_silhouette": false
    }
}

Upvotes: 4

Related Questions