Facebook Image URL gets expired
Asked Answered
T

3

46

I am pulling Facebook posts using facebook-graph API, now the problem is Image gets expired after few days.

I have the following URL for a single Image

Old Image URL which got expired

https://scontent-a.xx.fbcdn.net/hphotos-xfp1/v/l/t1.0-9/p180x540/14377_340369866155028_6836158858133154924_n.jpg?oh=7ed0d8818ad54fac851b036d24f5e674&oe=55579EE3

New Image working URL Is

https://scontent-sin1-1.xx.fbcdn.net/hphotos-xfa1/v/l/t1.0-9/14377_340369866155028_6836158858133154924_n.jpg?oh=2f7ad72fa36fc026ad2bdcc1b0284146&oe=55C87432

I am frustrated with this issue, what could be the solution of it?

Thaumaturgy answered 27/5, 2015 at 9:6 Comment(0)
T
52

What i came to know from other community about this issue is

"You should not store Facebook CDN URLs for long time use – they can change over time.

Either request the actual image and copy that to your server – or request the current CDN URL regularly.

(You might be tempted to try other workarounds, like extracting the actual image source URL from the CDN link, but I would advise against that – because the format of that might change at any time as well.)"

Thaumaturgy answered 27/5, 2015 at 15:14 Comment(5)
Where can I find more information about Facebook CDN restrictions? I couldn't find anything about not keeping facebook cdn urls for long time.Hayleyhayloft
@FranGarcía it's not a restriction per se, it's pragmatism. Nothing stops you from keeping them long, but there's no practical use for that since they will expire sooner or later.Elegancy
sure, but I am wondering if there is any way of extracting the long term one.Hayleyhayloft
@FranGarcía this seems to be a very good solution #34580636Elegancy
given the old url, how can I request the new one from the current CDN url?Nor
E
15

you can not store facebook Images url for a long time, it expires for security purpose, so it would be a better solution to store images in your server.

Extirpate answered 12/6, 2015 at 5:52 Comment(6)
For security purposes it's better to duplicate the image?Orator
@Orator I imagine it's for Facebook's security rather than yours. ;)Scalariform
I suppose it is for security of Facebook income. You don't hotlink, they don't pay for server processing nor bandwidth to serve that avatar image again and again.Bagger
But what's going to happen in any case where I need to display those images, I'm either going to request the image every time I need to serve it, in which case they are paying for processing and bandwidth every time, or I'm going to rerequest the image every few days, which could be more processing and bandwidth than just the hot links.Ifill
@Orator its abcxyz for security purpose, so it would be a better solution to store images in your server duplicate the image. Notice the comma You should read "Let's eat, Grandma!" instead of "Let's eat Grandma!"Bandbox
@PhamX.Bach as I much as I come to SO for grammar lessons, I think this might be a whoosh moment for you. Facebook don't expire images for security purposes. But thanks for tagging my 6 year old comment. I don't even know why I logged back into this legacy site...Orator
F
6

Haven't updated for a long time and don't know if this works as before

You should store the original image URL for sure, and use a 302 redirect parser to get the CDN URL, one example is https://scontent-ort2-1.xx.fbcdn.net/v/t45.1600-4/120202220_23846099766190042_1642096590788171162_n.jpg?_nc_cat=108&ccb=2&_nc_sid=2aac32&_nc_ohc=CE0J2Ao5cYkAX_JJ0Me&_nc_ht=scontent-ort2-1.xx&oh=f48cbb1bec21e685e0cbaaf6782a61a1&oe=5FE056E5 and we can just guess oe=5FE056E5 means the expiration, as 5FE056E5(hexadecimal) -> 1608537829(decimal, in UTC), if you interpret this timestamp you will find the time is about a month later, and maybe we can guess the expiration is about a month after getting the CDN URL? To another similar case, you can refer to: https://mcmap.net/q/63270/-how-to-efficiently-retrieve-expiration-date-for-facebook-photo-url-and-renew-it-before-it-expires

Fennessy answered 22/11, 2020 at 15:23 Comment(2)
There is also another type of URL that does not have an oe parameter. Any Idea how to find expiry for those URLs? For example - external-lcy1-1.xx.fbcdn.net/…Dilley
If I change the oe parameter value I'll get a "URL signature mismatch" error.Pindaric

© 2022 - 2024 — McMap. All rights reserved.