Logo Questions Linux Laravel Mysql Ubuntu Git Menu

Check if User's Facebook Profile Has Been Updated

I have a requirement to download and store the user's Facebook picture as we are using it in our system as their user account picture like a lot of other applications do.

The problem is I don't want to overwrite it every time I get an active session. What I would rather do is check somehow to see if the user has updated their profile picture since the last time I retrieved it. If they have then obviously I want to update the one I have in our system to match the current one on Facebook..

My Question

Is there an updated timestamp or something that I can look for to see when the user's Facebook profile picture was changed?

Is there a better way?


Going on @Nachi's advice, I made a Graph API request to the "/me/picture" graph endpoint and can successfully get back the user's profile image however it does not return an end tag in the header. Please see below for code.

Request.newGraphPathRequest(Session.getActiveSession(),"/me/picture",new Request.Callback() {
                public void onCompleted(Response response) {
                    Map<String,List<String>> headers = response.getConnection().getHeaderFields();
                    for (Map.Entry<String,List<String>> entry : headers.entrySet()) {
                        Log.d(LOG_TAG,entry.getKey()+": "+entry.getValue().toString());



I changed the end tag of the graph request to just /me which is the pubic profile and I did successfully get an ETag.

like image 221
StuStirling Avatar asked Mar 18 '23 01:03


2 Answers

You can use the Realtime API to get any changes, it does support checking for the profile picture: https://developers.facebook.com/docs/graph-api/real-time-updates/v2.1

It is much better than checking on your own on a regular basis, because Facebook will push changes to you instead and you will not have any problem with an API limit. In my experience, you get notified about changes in 30 seconds max, most of the times much faster.

like image 127
andyrandy Avatar answered Mar 21 '23 04:03


Yes, the Facebook Graph API supports HTTP ETags. When you make a call to the Graph API, you can supply a header parameter with a hash of the value from the last call. If the new value is unchanged, the server will return a 304 Not Modified.

Here's a detailed guide:

  1. When you make a Graph API call, the response header includes ETag with a value that is the hash of the data returned in the API call. Pull this ETag value and use in Step-2.
  2. Next time you make the same API call, include the If-None-Match request header with ETag value pulled from step-1 for this API call.
  3. If the data hasn’t changed, the response status code would be 304 – Not Modified and no data is returned.
  4. If the data has changed since last pull, the data is returned as usual with a new ETag. Pull the new ETag value and use for subsequent calls.
like image 22
Nachi Avatar answered Mar 21 '23 04:03