Thursday, April 6, 2017

Facebook API Private Message image expired - How to get new image ? URL signature expired

Leave a Comment

I'm helping maintain an app that integrates with Facebook, and has lots of archived links to old private message images. Sometimes these images expire, and we go to facebook and request a new image. This works 90% of the time.

About 10% of the time we're getting back a response that we can't tell what the new image is.

What's the proper way to request a new url for an expired Facebook Private Message image, preferably using v2.5 or newer of the Graph API?

Currently we're doing a GET request to Facebook's Graph API using the message id of the private message like so:

https://graph.facebook.com/v2.3/m_mid.XXXXXXXXX:YYYYYYYYY

and that gives us a response that has a bunch of attachments in it. For 90% of use cases, there's a new attachment that has an url or name field with a new filename that contains the old filename, e.g. old file name being XXX, we'd see a new filename like ....XXXX.... in the url field.

attachments [url='*%s*']/image_data/url attachments [name='*%s*']/image_data/url 

or sometimes

picture 

but that doesnt match what we get now, which is a bunch of attachments with no way to map to the new image.

1 Answers

Answers 1

We haven't been able to find a graph API way of doing this, but have the following solutions we're considering:

  • When there's only one attachment in the response, we just use that one url. This works some of the time, but fails when there's more than one image of course

  • Save more metadata about the image, at worst case an MD5 of the file. Then compare that to MD5's of the other files until we get the one we want. Instead of an MD5, we could consider using info about the file from a HEAD request. All of this is untested.

  • Update our old message metadata with new metadata whenever this happens, thus avoiding the problem entirely as new image requests would come from the new metadata.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment