Answer the question
In order to leave comments, you need to log in
Why Instagram API changes code and token?
Hello. I'm trying to get an access token through a script, because if I got it manually, then after a while it changed.
To get a token, I need client_id, client_secret, redirect_uri, code.
1, 2 and 3 are in the application. To get the code, I go to the url https://www.instagram.com/oauth/authorize/?client_... and after the redirect I take the received data. But they change every time after some time, and because of this, I cannot enter the actual data in the PHP code below.
Then I try to get the access token like this
$fields = array(
'client_id' => 'МОЙ-CLIENT-ID',
'client_secret' => 'МОЙ-CLIENT-SECRET',
'grant_type' => 'authorization_code',
'redirect_uri' => 'МОЙ-REDIRECT-URI',
'code' => 'МОЙ-CODE'
);
$url = 'https://api.instagram.com/oauth/access_token';;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
$result = curl_exec($ch);
curl_close($ch);
$result = json_decode($result);
$token = $result->access_token; //your token
Answer the question
In order to leave comments, you need to log in
changes because it is the Oauth standard
updated, of course, it is obtained by a script
Oauth involves a request to get a new token, but the instagram developers apparently do not know about this and did not provide the opportunity to get it through a request. There they have written about obtaining a key on the server side and on the client side. Only as a server they use a client, that is, a browser for authorization through the user's login and password.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question