R
R
r4gn4r0k2018-08-23 20:55:10
API
r4gn4r0k, 2018-08-23 20:55:10

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

Is it possible to get CODE also via PHP, instead of manually?
Or MB, I do not understand everything correctly, while it is correct to obtain an access token'a?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dimonchik, 2018-08-23
@dimonchik2013

changes because it is the Oauth standard
updated, of course, it is obtained by a script

P
Puma Thailand, 2018-08-24
@opium

If the token is expired just get a new one

N
No_Bugs, 2019-10-07
@No_Bugs

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 question

Ask a Question

731 491 924 answers to any question