can somebody tell me please how can I get images from my own Instagram via PHP? I have login name, password, app id, app secret. IG changed the api so all the documentation including how to get access token does not work. 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
This endpoint should work to query the user's media: GET /{ig-user-id}/media
giving you a list of media ids:
{
"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.
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
Get your authorization code either via a Login Window or via a facebook app (described below)
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
Instagram Basic Display
and fill out all necessary fields Within the section Basic Display
of the Instagram Basic Display
product you will find your App ID
and Secret
Below that you can enter your redirect_uri
[...]quickly generate long-lived Instagram User Access Tokens for any of your public Instagram accounts. This is useful if you [...] don't want to bother with implementing the Authorization Window [...] See Instagram Basic Display API Docs
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.