Update to My Launch Center Pro Action to Get URLs from the Instagram API

Home

This post was originally published on my Postach.io blog on December 18th, 2014.

Since I wrote the original Launch Center Pro action to get either the URL scheme or image URL for an Instagram post, Instagram has added more metadata to their API page. This has resulted in breakage of the URL action when one wants to get the raw image URL. (Please read the original post, because none of what follows will make sense otherwise.)

Now, the info for the same API URL I referenced in the original post offers the following:

{"provider_url":"http:\/\/instagram.com\/","media_id":"759343924702114562_1483611","title":"Another beautiful day in the city! \ud83d\ude0d","thumbnail_height":640,"html":"\u003cblockquote class=\"instagram-media\" data-instgrm-captioned data-instgrm-version=\"4\" style=\" background:#FFF; border:0; border-radius:3px; box-shadow:0 0 1px 0 rgba(0,0,0,0.5),0 1px 10px 0 rgba(0,0,0,0.15); margin: 1px; max-width:658px; padding:0; width:99.375%; width:-webkit-calc(100% - 2px); width:calc(100% - 2px);\"\u003e\u003cdiv style=\"padding:8px;\"\u003e \u003cdiv style=\" background:#F8F8F8; line-height:0; margin-top:40px; padding:50% 0; text-align:center; width:100%;\"\u003e \u003cdiv style=\" background:url(data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAACwAAAAsCAMAAAApWqozAAAAGFBMVEUiIiI9PT0eHh4gIB4hIBkcHBwcHBwcHBydr+JQAAAACHRSTlMABA4YHyQsM5jtaMwAAADfSURBVDjL7ZVBEgMhCAQBAf\/\/42xcNbpAqakcM0ftUmFAAIBE81IqBJdS3lS6zs3bIpB9WED3YYXFPmHRfT8sgyrCP1x8uEUxLMzNWElFOYCV6mHWWwMzdPEKHlhLw7NWJqkHc4uIZphavDzA2JPzUDsBZziNae2S6owH8xPmX8G7zzgKEOPUoYHvGz1TBCxMkd3kwNVbU0gKHkx+iZILf77IofhrY1nYFnB\/lQPb79drWOyJVa\/DAvg9B\/rLB4cC+Nqgdz\/TvBbBnr6GBReqn\/nRmDgaQEej7WhonozjF+Y2I\/fZou\/qAAAAAElFTkSuQmCC); display:block; height:44px; margin:0 auto -44px; position:relative; top:-22px; width:44px;\"\u003e\u003c\/div\u003e\u003c\/div\u003e \u003cp style=\" margin:8px 0 0 0; padding:0 4px;\"\u003e \u003ca href=\"https:\/\/instagram.com\/p\/qJu0a-OHMC\/\" style=\" color:#000; font-family:Arial,sans-serif; font-size:14px; font-style:normal; font-weight:normal; line-height:17px; text-decoration:none; word-wrap:break-word;\" target=\"_top\"\u003eAnother beautiful day in the city! \ud83d\ude0d\u003c\/a\u003e\u003c\/p\u003e \u003cp style=\" color:#c9c8cd; font-family:Arial,sans-serif; font-size:14px; line-height:17px; margin-bottom:0; margin-top:8px; overflow:hidden; padding:8px 0 7px; text-align:center; text-overflow:ellipsis; white-space:nowrap;\"\u003eA photo posted by newyorkcity (@newyorkcity) on \u003ctime style=\" font-family:Arial,sans-serif; font-size:14px; line-height:17px;\" datetime=\"2014-07-07T13:47:51+00:00\"\u003eJul 7, 2014 at 6:47am PDT\u003c\/time\u003e\u003c\/p\u003e\u003c\/div\u003e\u003c\/blockquote\u003e\n\u003cscript async defer src=\"\/\/platform.instagram.com\/en_US\/embeds.js\"\u003e\u003c\/script\u003e","author_name":"newyorkcity","height":null,"thumbnail_width":640,"width":658,"version":"1.0","author_url":"http:\/\/instagram.com\/newyorkcity","author_id":1483611,"thumbnail_url":"http:\/\/photos-d.ak.instagram.com\/hphotos-ak-xap1\/t51.2885-15\/10537269_595401073912091_331298792_n.jpg","type":"rich","provider_name":"Instagram"}

Splitting this with a " no longer works if one wants to always get the image URL at a specific line number. However, the image URL is still pretty easy to find here if you know HTML. It’s at the end:

http:\/\/photos-d.ak.instagram.com\/hphotos-ak-xap1\/t51.2885-15\/10537269_595401073912091_331298792_n.jpg


I’m sure there’s a way to pull this via regex or something, but for now, I’ve updated the original LCP action with this hack: Replace the end of the LCP URL action with

|image=texttool://x-callback-url/transform?text=[clipboard]&method=unescape&x-success={{drafts:///create?text=[[output]]}}]


where |image=texttool starts, up to and including the end. (Or you can import the updated LCP URL action.)

After you run the script, instead of selecting all the code in Textastic, just select the escaped image URL (as in above) and copy it to your clipboard. Then after double-tapping and returning to Launch Center Pro, choose “image” and TextTool will unescape the URL and return it to Drafts.