[英]How to get images from my own Instagram with PHP?
can somebody tell me please how can I get images from my own Instagram via PHP?有人可以告诉我如何通过 PHP 从我自己的 Instagram 获取图像吗? I have login name, password, app id, app secret.我有登录名、密码、应用程序 ID、应用程序机密。 IG changed the api so all the documentation including how to get access token does not work. IG 更改了 api,因此包括如何获取访问令牌在内的所有文档都不起作用。 I have this peace of code:我有这样的代码和平:
$fb = new \Facebook\Facebook([
'app_id' => self::APP_ID_IG,
'app_secret' => self::APP_SECRET_IG,
'default_graph_version' => 'v2.10',
]);
// This return string which creates access token as "app_id value|app_secret value"
$token = $fb->getApp()->getAccessToken();
// This line throws me an error:
// Error validating application. Cannot get application info due to a system error.
$response = $fb->get('https://graph.instagram.com/me/media?fields=media_url,media_type', $token->getValue());
I am lost in it.我迷失在其中。 Thanks for help.感谢帮助。
You should take a look at the Instagram's Media API你应该看看Instagram 的 Media API
This endpoint should work to query the user's media: GET /{ig-user-id}/media
giving you a list of media ids:此端点应该用于查询用户的媒体: GET /{ig-user-id}/media
为您提供媒体 ID 列表:
{
"data": [
{
"id": "17895695668004550"
},
{
"id": "17899305451014820"
},
{
"id": "17896450804038745"
},
{
"id": "17881042411086627"
},
{
"id": "17869102915168123"
}
]
}
After that, I think you sould use the graph API to get the image URL of each media id.之后,我认为您应该使用图形 API 来获取每个媒体 ID 的图像 URL。
I created a vuejs adaption a while back, maybe this code structure snippet helps you since I don't have time right now to translate it into php
, it is written in javascript
but the API requests remain the same (just use curl
instead of axios
): https://gitlab.com/-/snippets/1957175不久前我创建了一个 vuejs 适配,也许这个代码结构片段可以帮助你,因为我现在没有时间将它翻译成php
,它是用javascript
编写的,但 API 请求保持不变(只需使用curl
而不是axios
): https://gitlab.com/-/snippets/1957175
Get your authorization code either via a Login Window or via a facebook app (described below)通过登录窗口或 Facebook 应用程序获取您的授权码(如下所述)
Transform it into a shortterm access token
curl --request POST \
--url 'https://api.instagram.com/oauth/access_token?grant_type=authorization_code&client_id=[CLIENT_ID_HERE]&client_secret=[CLIENT_SECRET_HERE]&redirect_uri=[REDIRECT_URI_HERE]&code=[AUTHORIZATION_CODE_HERE]' \
--header 'Content-Type: multipart/form-data' \
--form client_id=[CLIENT_ID_HERE] \
--form client_secret=[CLIENT_SECRET_HERE] \
--form code=[AUTHORIZATION_CODE_HERE] \
--form grant_type=authorization_code \
--form redirect_uri=https://[REDIRECT_URI_HERE]/
GET https://graph.instagram.com/access_token?grant_type=ig_exchange_token&access_token=[SHORTTERM_ACCESS_TOKEN_HERE]&client_secret=[CLIENT_SECRET_HERE]
GET https://graph.instagram.com/refresh_access_token?grant_type=ig_refresh_token&access_token=[OLD_ACCESS_TOKEN_HERE]
For more info about which field to add to the query check the official facebook documentation有关将哪个字段添加到查询中的更多信息,请查看官方 facebook 文档
Instagram Basic Display
and fill out all necessary fields在产品下,添加Instagram Basic Display
并填写所有必填字段 Within the section Basic Display
of the Instagram Basic Display
product you will find your App ID
and Secret
在Instagram Basic Display
产品的Basic Display
部分中,您将找到您的App ID
和Secret
Below that you can enter your redirect_uri
您可以在下方输入您的redirect_uri
[...]quickly generate long-lived Instagram User Access Tokens for any of your public Instagram accounts. [...] 为您的任何公共 Instagram 帐户快速生成长期存在的 Instagram 用户访问令牌。 This is useful if you [...] don't want to bother with implementing the Authorization Window [...] See Instagram Basic Display API Docs如果您 [...] 不想为实现授权窗口而烦恼,这将很有用 [...] 请参阅 Instagram 基本显示 API 文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.