Reputation: 125
I have got the code using url: https://api.instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=code
After that on Instagram Documentation this code is given:
curl -F 'client_id=CLIENT_ID' \
-F 'client_secret=CLIENT_SECRET' \
-F 'grant_type=authorization_code' \
-F 'redirect_uri=AUTHORIZATION_REDIRECT_URI' \
-F 'code=CODE' \
https://api.instagram.com/oauth/access_token
How to use it in PHP?
Upvotes: 3
Views: 11083
Reputation: 71
$fields = array(
'client_id' => 'YOUR-CLIENT-ID',
'client_secret' => 'YOUR-CLIENT-SECRET',
'grant_type' => 'authorization_code',
'redirect_uri' => 'YOUR-REDIRECT-URI',
'code' => 'YOUR-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);
return $result->access_token; //your token
Upvotes: 7