31

I am using Instagram feed API to show my Instagram posts on my Website. But some video URL shows 'URL signature expired'.

Any solution for me ?

0

4 Answers 4

29

You could use the media URL with some extra parameters as a solution to get the desired image instead of using the direct image link.

For example

https://www.instagram.com/p/Bo7OXJ3hYM8/media/?size=m

Notice the addon /media/?size=m

Letters could be t, m or l for different picture sizes

This should return you the desired image

Reference: https://www.instagram.com/developer/embedding/

2
  • 1
    This works only on images, but not on reels/videos.. Any solution for the same? Sep 28, 2022 at 21:12
  • How can we specify the image we want in a multi-image post?
    – GGGforce
    Sep 29, 2023 at 7:50
18

Instagram has added URL signatures to their media URLs.

You can easily remove the URL signature using this regular expression: "vp.*/.{32}/.{8}/"

For example in PHP:

preg_replace('/vp.*\/.{32}\/.{8}\//', '', $mediaUrl)

On the other hand, I don't think that removing the URL signature is the best solution (is just a quick fix). The good one is to call again the Instagram api in order to get the new URL.


UPDATE

It seems that Instagram is currently checking the URL signature and returns a 403 "Access denied" error if the signature is not present, so now the only solution is to call the Instagram API again in order to get the new media URL.

UPDATE April 2018

Instagram has closed their "api.instagram.com/v1/media/" endpoint so now it's currently not possible to update the posts urls.

A possible solution is to download the media and store them in your own servers (I do not recommend this solution because it violates the terms of the Instagram API so do this at your own risk).

Another solution is to call the original endpoint where you have find the medias again (but currently it's difficult to manage the calls with the new API rate limit).

Also you can find some non-official Instagram APIs on github that could help you.

5
  • Do you know what is the motivation for them using URL signatures in the first place? I wonder what happens if we fetch the media without the signature.
    – zaboco
    Mar 20, 2018 at 13:36
  • 1
    @zaboco probably they don't want that the applications store the media URLs.
    – Jordi
    Mar 26, 2018 at 12:05
  • 1
    @ZorleQ you're right, it seems that this doesn't work anymore, so the only solution is to call the Instagram API again in order to get the new media URLs.
    – Jordi
    Mar 26, 2018 at 12:05
  • 2
    You might want to add that getting new URL is also not always possible now. Instagram closed the getting post by ID endpoint api.instagram.com/v1/media/<id>. In my case, I collect by tags, so /recent endpoint will not always return posts that I want to refresh.
    – yagger
    Apr 10, 2018 at 4:25
  • You are right @yagger, I will edit the answer later during this week. Thank you for the update! :)
    – Jordi
    Apr 16, 2018 at 9:35
5

At the time of writing, your only alternative is to store or cache the images somehow.

For example, you could store the images in your database. Instagram platform policy requires that you delete the images when your application no longer needs them.

Alternatively, if you use a CDN you can serve these images through an image proxy and then set long expiry dates on the CDN. This way you are not storing the images in a database, but your users can still see them after the URL signature expires.

1
  • Is storing images against the terms or not ?
    – younes0
    Nov 20, 2022 at 12:06
-1

There're backward slashes in the given URL. If you remove them, it would work. For example, URL given by the API was:

https:\/\/scontent.cdninstagram.com\/v\/t51.29350-15\/3304...

So, I made it to this:

https://scontent.cdninstagram.com/v/t51.29350-15/3304...

And it worked.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.