Instagram Get Access Token from Code in PHP

丶灬走出姿态 提交于 2019-12-04 13:51:41

Since it's https already so you need to put this on your code

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);  
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, false);

It's not about your redirect uri is in local or not. It's because SSL_VERIFYPEER is not set in your curl option

Well there are a few issues with your code. For one it seems like your redirect_uri is localhost. Obviously localhost to Instagram is their own servers. You need to provide a FQDN/world accessible url.

Also from http://php.net/manual/en/function.curl-setopt.php the code

curl_setopt($ch, CURLOPT_POST, count($apiData));

Should simple be

curl_setopt($ch, CURLOPT_POST, 1);

Your code is correct, but you need change

$redirect_uri = 'your site addres (not localhost)';

Example:

$client_id        = 'YOUR_CLIENT_ID';
$client_secret    = 'YOUR CLIENT SECRET';
$redirect_uri     = 'http://www.YOUR_SERVER.com/instagram/demo.php';
$scope            = 'basic+likes+comments+relationships';

If you execute this script with this change you can obtain this result.

stdClass Object
(
    [access_token] => 'your_ID'.xxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    [user] => stdClass Object
        (
            [username] => 'your username'
            [bio] => 
            [website] => 
            [profile_picture] => 'your url picture profile' 
            [full_name] => 
            [id] => 'your_ID'
        )

)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!