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?
UPDATE
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() {
@Override
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());
}
Log.d(LOG_TAG,response.getRawResponse());
Log.d(LOG_TAG,response.getGraphObject().toString());
}
}
).executeAsync();
UPDATE 2
I changed the end tag of the graph request to just /me which is the pubic profile and I did successfully get an ETag.
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.
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:
- 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.
- 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.
- If the data hasn’t changed, the response status code would be 304 – Not Modified and no data is returned.
- 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With