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 ?

Gal Margalit
  • 5,525
  • 6
  • 52
  • 56
Arun Singh
  • 311
  • 1
  • 3
  • 5

4 Answers4

28

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/

missmatsuko
  • 148
  • 1
  • 5
Vladimir Afinello
  • 1,211
  • 14
  • 16
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.

demo
  • 6,038
  • 19
  • 75
  • 149
Jordi
  • 1,108
  • 1
  • 8
  • 18
  • 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 '18 at 13:36
  • 1
    @zaboco probably they don't want that the applications store the media URLs. – Jordi Mar 26 '18 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 '18 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 https://api.instagram.com/v1/media/. In my case, I collect by tags, so /recent endpoint will not always return posts that I want to refresh. – yagger Apr 10 '18 at 04:25
  • You are right @yagger, I will edit the answer later during this week. Thank you for the update! :) – Jordi Apr 16 '18 at 09: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.

Pirkka Esko
  • 718
  • 9
  • 13
0

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.

Moritz Ringler
  • 9,772
  • 9
  • 21
  • 34