【发布时间】:2014-07-03 21:52:40
【问题描述】:
背景
我有一段 (jQuery) ajax 代码已经愉快地工作了大约 9 个月,直到最后几周左右。
此代码使用 Instagram 的 embedding endpoints,它允许我从普通 Instagram 链接(如 http://instagram.com/p/BUG/)中获取媒体源(图像或视频),无论用户是谁,并且无需需要 access_token .
简化示例:
var URL = "http://api.instagram.com/oembed?url=http://instagram.com/p/BUG/";
$(document).ready(function () {
$.ajax({
url: URL,
dataType: "jsonp",
cache: false,
success: function (response) {
console.log(response.url);
},
error: function () {
console.log("couldn't process the instagram url");
}
});
});
在上面的代码中,response.url 将返回完整的媒体 URL 源,如:
http://photos-a.ak.instagram.com/xxxx/1234_123456123_123456_n.jpg // image or
http://distilleryvesper3-15.ak.instagram.com/b0c957463548362858_101.mp4 // video
然后我可以使用返回的 URL 将媒体文件嵌入到我的网页中。
注意:
由于我们的想法是获取任何 Instagram 链接的 URL 源,而与用户无关,因此不能使用 media endpoints。
问题
Instagram 的 oembed 端点允许您获取 json 响应,在过去几周之前它的结构是这样的:
{
"provider_url" : "http:\/\/instagram.com\/",
"media_id" : "123456789_123456789",
"title" : "the title",
"url" : "http:\/\/photos-a.ak.instagram.com\/hphotos-ak-xfp1\/12345678_123456789012345_1234567890_n.jpg",
"author_name" : "{the user name}",
"height" : 640,
"width" : 640,
"version" : "1.0",
"author_url" : "http:\/\/instagram.com\/{the user name}",
"author_id" : 123456789,
"type" : "photo",
"provider_name" : "Instagram"
}
您可能已经注意到,我的 ajax 代码对属性名称 url 特别感兴趣,它包含完整的媒体 URL。
注意此json 回复(与今天一样)对于 Instagram 图片仍然有效,然而,如果原始 Instagram 的链接是视频,让我们使用真实的例如:http://instagram.com/p/mOFsFhAp4f/ (CocaCola(c)) json 响应不再返回任何 url 键。
似乎在引入web embeds 之后,Instagram 已决定在他们的(oembed)json 响应中仅对视频的 html 属性替换键 url,其中包含要嵌入的 iframe,如下所示:
{
...
"html" : "\u003ciframe src=\"http:\/\/instagram.com\/p\/BUG\/embed\" width=\"616\" height=\"716\" frameborder=\"0\" scrolling=\"no\" allowtransparency=\"true\"\u003e\u003c\/iframe\u003e",
...
}
...当然,这会破坏我的代码,因为 response.url 未定义。
问题
Instagram json 响应发生变化后如何获取完整视频的 URL?
很遗憾,我在 Instagram 的开发者网站上找不到任何合适的文档或更改日志(他们有很棒的 API,但文档很差。)
请注意问题是关于 Instagram API (v1) 嵌入端点而不是 jQuery 或 ajax 问题。
我正在寻找(可能是未记录的)Instagram 的 API 选项、端点、oembed 或其他(不需要access_token),它允许我检索到媒体视频的直接链接(最好在 json 响应之后)无论用户...或愿意考虑一个不太老套的解决方法,都脱离了正常的 Instagram 链接。
【问题讨论】:
-
我看到
BUG键是shortcode键。你改了吗? -
@MortezaN.Alamdari :如果您知道我的意思,请查看Instagram documentation。
BUG是媒体 ID 的简码(可以是mOFsFhAp4f中的任何 instagram.com/p/mOFsFhAp4f ) -
为什么不检查媒体类型,然后决定是否需要
response.url或response.html? -
@Jashwant :当然可以,但
response.html是iframe。我正在寻找的应该看起来像http://distilleryvesper3-15.ak.instagram.com/b0c957463548362858_101.mp4。你能从iframe中得到它吗? (当然没有 Firebug,但来自应用程序;)如果是这样,请发布您的答案。 -
您不想使用
embed链接并想要一个带有mp4链接的网址? This code 不适合你。对吧?
标签: jquery ajax instagram endpoints oembed