我找不到与Instagram Reels
相关的API
。是否有人知道是否存在此API,或者将来是否会有?
目前,Facebook
开发者文档中没有提到任何关于Instagram Reels
的信息。
https://developers.facebook.com/docs/instagram-api/overview/
我找不到与Instagram Reels
相关的API
。是否有人知道是否存在此API,或者将来是否会有?
目前,Facebook
开发者文档中没有提到任何关于Instagram Reels
的信息。
https://developers.facebook.com/docs/instagram-api/overview/
更新的答案:
现在通过API支持Reels,它于2022年7月6日正式发布。请参阅https://developers.facebook.com/blog/post/2022/06/27/introducing-reels-apis-to-instagram-platform/。
原始回答:
在Instagram API文档中,目前在限制中写着“不支持Reels”。
Reels是指类型为“VIDEO”的IG Media。
如果您知道他的Facebook Media ID(不是Instagram的Media ID),您可以获取单个“Reels”。
如果Reels像stories一样发布,您可以从stories endpoint(GET graph.facebook.com/{ig-user-id}/stories)获取媒体列表。您将获得媒体ID的数组。
"data": [
{
"id": "{ig-media-id}"
},
...
]
}
然后您可以从单个媒体对象端点(GET /{ig-media-id})获取信息。
所以目前只有当reels像story一样发布时,您才能通过API获取它们。
无论如何,在某些国家/地区中不支持reels,您只能从这些国家/地区的stories中查看reels。
更新
当您从business-discovery(GET {ig-user-id}?fields=business_discovery.username(instagramm_user_name){media{id,permalink,media_type,media_url}}
)或用户媒体(GET /{ig-user-id}/media
)中检索用户媒体时,也可以获得reels。
如果媒体的永久链接看起来像https://www.instagram.com/reel/...
并且media_type为VIDEO
,那么它就是reels。
我不确定,但我查找了一个Instagram的.ipa文件,并找到了这些URL方案参数。
instagram://reels_home
instagram://reels_share
如果在iOS上单击这两个,都会带您进入Reels Feed。我的意图是打开Reels相机(或将模式设置为Reels的故事相机),但我猜目前我们只能访问Reels Feed。
如前所述,Instagram不提供直接的API,但您可以借助Instagrapi来获得帮助,它非常棒且易于使用。注意:这个Instagram私有API包装器是用Python编写的。 以下是如何使用它 - 安装库:
python -m pip install instagrapi
代码
from instagrapi import Client
cl = Client()
#enter your username and password
cl.login('username', 'password')
#you can replace 10 with whatever amount of reels you want to fetch
reel = cl.explore_reels(amount = 10)
print(reel)
就是这样!!!
Meta刚刚发布了Instagram平台的Reels API。
https://developers.facebook.com/blog/post/2022/06/27/introducing-reels-apis-to-instagram-platform/
嗨,
Instagram目前还没有提供任何Reels API,因为许多国家仍未提供Reels功能,但这很快就会有所改变。
问题是,在没有API的情况下,我们如何通过API获取reels数据?
答案是您无法获取。但是!如果您想进行一些爬取操作,那么答案肯定是可以的!
但是怎样操作呢?
我们都知道,爬取需要付出大量的努力,因为事物经常发生变化。如果您不在意这些,以下是用于获取JSON中reels数据的示例PHP脚本。
<?php
//!IMPORTANT
$sessionid = ["Cookie: sessionid=YOUR SESSION ID HERE"];
// REELS SHORT CODE FROM URL
$shortcode = null;
$response = [];
/**
* Get a web file (HTML, XHTML, XML, image, etc.) from a URL. Return an
* array containing the HTTP server response header fields and content.
*/
function get_web_page($url)
{
$user_agent = 'Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0';
$options = array(
CURLOPT_CUSTOMREQUEST => "GET", //set request type post or get
CURLOPT_POST => false, //set to GET
CURLOPT_USERAGENT => $user_agent, //set user agent
# CURLOPT_COOKIEFILE => "cookie.txt", //set cookie file
# CURLOPT_COOKIEJAR => "cookie.txt", //set cookie jar
CURLOPT_HTTPHEADER => $sessionid, // sending manually set cookie
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect
CURLOPT_TIMEOUT => 120, // timeout on response
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
);
$ch = curl_init($url);
curl_setopt_array($ch, $options);
$content = curl_exec($ch);
$err = curl_errno($ch);
$errmsg = curl_error($ch);
$header = curl_getinfo($ch);
curl_close($ch);
$header['errno'] = $err;
$header['errmsg'] = $errmsg;
$header['content'] = $content;
return $header;
}
if ((isset($_GET['q'])) && !empty($_GET['q'])) {
$shortcode = $_GET['q'];
$reels_url = "https://www.instagram.com/p/$shortcode/?__a=1";
// read a web page and check for errors:
$result = get_web_page($reels_url);
if ($result['errno'] != 0) {
$response = json_encode(['error' => "bad url, timeout, redirect loop"]);
}
if ($result['http_code'] != 200) {
$response = json_encode(['error' => "no page, no permissions, no service"]);
}
if ($result['http_code'] === 200) {
$response = $result['content'];
}
}
// JSON OUTPUT OR ERROR HERE
header('Content-Type: application/json');
echo $response;
如何使用这个PHP脚本?
将上面的脚本保存在一个PHP文件中,例如fetch-reels.php
,并像下面这样运行它
http://localhost/fetch-reels.php?q={SHORT-CODE}
卷轴URL,例如
Instagram刚刚发布了Reels支持(自2022年7月7日起对所有用户开放)。
更多信息请参见此处: https://developers.facebook.com/docs/instagram-api/guides/content-publishing/
更新 (2022年7月14日):Meta(Facebook)通过其官方Graph API推出了对Reels的支持。在此处阅读更多信息:https://developers.facebook.com/docs/instagram-api/reference/ig-user/media#reel-specifications
Instagram Reels API现已正式推出:
https://developers.facebook.com/blog/post/2022/06/27/introducing-reels-apis-to-instagram-platform/
你可以制作一个定时发布的帖子。例如,使用JavaScript并上传视频到Reels API [1]:
const access_token = "Js82ks92jald"; // The access token given from FB
const instagram_user_id = "12345"; // The IG user's ID
const reelUrl = "https://www.website.com/reel.mp4";
const caption = "This is the best real ever #Reels4Real";
const postUrl = `https://graph.facebook.com/${instagram_user_id}/media?video_url=${encodeURIComponent(reelUrl)}&caption=${encodeURIComponent(caption)}&access_token=${access_token}&media_type=REELS&share_to_feed=true&thumb_offset=2000`;
const postOptions = {
method: "POST",
headers: {
"Content-Type": "application/json",
},
};
fetch(postUrl, postOptions)
.then((res) => res.json())
.then(json => console.log(json))
.catch(console.error);