UPDATED: Script to Get URL Scheme and Direct Image Link for an Instagram Post


posted May 13, 2015

Last summer I wrote a complicated iPhone URL action sequence to get the URL scheme and direct image link for an Instagram post. And then later I updated it. (With the URL scheme, you can tap on the link while on your iOS device and go directly to that post in the Instagram app.)

Now that I know more javascript, I've written a script to automate this process so that you don't need to use iOS apps like TextTool, Drafts and Textastic (however great these apps are) just to get these two URLs.

Now all you have to do is add the URL of an Instagram post to the end of the query at http://javascript.jeffreykishner.com/getInstagramYQL.html?url=.

For example, if I want the URL scheme and direct image link for this Beyonce post, I just add https://instagram.com/p/1gL1RVPw9P/?taken-by=beyonce to the end of the query so that it looks like this in the browser: http://javascript.jeffreykishner.com/getInstagramYQL.html?url=https://instagram.com/p/1gL1RVPw9P/?taken-by=beyonce.

View the results.

How to Easily Do This on Your iPhone

To save time, you will want to install this URL action in Launch Center Pro or create this new URL action:


In Instagram for iOS, tap on the ellipses under an image, then tap on "Copy Share URL." Then go to Launch Center Pro and tap on the Instagram action you just installed. It will bring you to the script page with the two links associated with that post.

Javascript Bookmarklet

When you're viewing Instagram in a browser, you can use this bookmarklet. Bookmark any page, then go into Edit and replace the URL with the following:


The Geeky Stuff You Don't Need to Read to Make the Script Work

The Instagram API does not support Cross Origin Resource Sharing, and after several hours of frustration I have not been able to figure out how to do more than a simple xmlhttprequest. However, the Yahoo Query Language API is a useful workaround.

For example, the following statement yields the JSON from the Instagram API for the above Beyonce image:

select * from json where url="http://api.instagram.com/oembed?url=http://instagram.com/p/qJu0a-OHMC"

For the script, I pulled out the URL-encoded Instagram post link and stuck in a variable to pass the query string into the URL.

var url="https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20json%20where%20url%3D%22http%3A%2F%2Fapi.instagram.com%2Foembed%3Furl%3D" + encodeURIComponent(y[1]) + "%22&format=json&diagnostics=true&callback=";