【问题标题】:Instagram getting Access token Notice: Undefined index: access_tokenInstagram 获取访问令牌通知:未定义索引:access_token
【发布时间】:2015-04-06 10:03:06
【问题描述】:

我是初级程序员

为了获得 Instagram 身份验证,我在我的服务器上上传了这个 php 代码

<?php 

getAccessToken();

function getAccessToken(){

if($_GET['code']) {
    $code = $_GET['code'];
    $url = "https://api.instagram.com/oauth/access_token";
    $access_token_parameters = array(
            'client_id'                =>     'b7f14786b7754f04aa43dcxxxxxxxxxx', // my client id
            'client_secret'            =>     '33987fcae22949a9b3682bxxxxxxxxxx', // secret key
            'grant_type'               =>     'authorization_code',
            'redirect_uri'             =>     'http://thedreamkr.com/',
            'code'                     =>     $code
    );
    $curl = curl_init($url);    // we init curl by passing the url
    curl_setopt($curl,CURLOPT_POST,true);   // to send a POST request
    curl_setopt($curl,CURLOPT_POSTFIELDS,$access_token_parameters);   // indicate the data to send
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);   // to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);   // to stop cURL from verifying the peer's certificate.
    $result = curl_exec($curl);   // to perform the curl session
    curl_close($curl);   // to close the curl session

    $arr = json_decode($result,true);
    echo "access_Token: ".$arr['access_token']; // display the access_token
    echo "<br>";   
    echo "user_name : ".$arr['user']['username'];   // display the username
}
}

?>

当我访问“https://api.instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=code”时

它返回以下错误

Notice: Undefined index: access_token in /home/ubuntu/php/hashberry/token.php on line 26 
access_Token:
Notice: Undefined index: user in /home/ubuntu/php/hashberry/token.php on line 28
user_name : 

【问题讨论】:

    标签: php oauth-2.0 instagram instagram-api


    【解决方案1】:

    经过测试,您的代码可以完美运行。

    但是: 1-您需要将代码放在与您的网站 URI 不同的重定向 URI 中。 2- 更改您的重定向 uri 以匹配您注册的应用程序中的那个。

    例如: 网址:https://example.com/
    重定向 URI:https://example.com/register/

    祝你好运

    【讨论】:

      猜你喜欢
      • 2016-10-22
      • 2017-04-28
      • 2016-02-02
      • 1970-01-01
      • 1970-01-01
      • 2016-10-24
      • 1970-01-01
      相关资源
      最近更新 更多