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.
My Answer:
Unfortunately, Instagram has made changes to their API which now requires all apps to go through a review process before being able to access user data. This means that you will need to submit your app for review and get approval before you can access your own Instagram data via PHP.
In the meantime, you can try using the Instagram Basic Display API which allows you to access a limited set of user data without going through the review process. You can follow the steps outlined in the Instagram Basic Display API documentation to set up your app and get an access token.
Once you have your access token, you can use it to make API requests to retrieve your own Instagram images. Here is an example of how you can modify your code to use the Instagram Basic Display API:
php
$fb = new \Facebook\Facebook([
'app_id' => self::APP_ID_IG,
'app_secret' => self::APP_SECRET_IG,
'default_graph_version' => 'v9.0',
]);
$token = 'YOUR_ACCESS_TOKEN';
$response = $fb->get('https://graph.instagram.com/me/media?fields=media_url,media_type', $token);
$data = $response->getDecodedBody();
foreach ($data['data'] as $post) {
echo '';
}
Remember to replace 'YOUR_ACCESS_TOKEN' with the access token you obtained from the Instagram Basic Display API. This code should allow you to retrieve and display your own Instagram images using PHP.
Rate this post
4 of 5 based on 6031 votesComments