如何从Instagram生成访问令牌

时间:2020-07-23 18:16:30

标签: javascript php api instagram-api

我想使用以下代码生成访问令牌。它给了我一个错误{"error_type": "OAuthException", "code": 400, "error_message": "Invalid scope: []"}
有什么不对的吗? 在哪里可以获得确切的重定向URI? 预先感谢。

<a id="button" class="instagram-token-button" href="https://api.instagram.com/oauth/authorize/?client_id=829725617557773&redirect_uri=https://stninternational.com/instafeed&response_type=code">Click here to get your Instagram Access Token and User ID</a>
<?PHP
  if (isset($_GET['code'])) {

        $code = $_GET['code'];

        $client_id='829725617557773';
        $redirect_uri='https://stninternational.com/instafeed/';
        $client_secret='ab1b7d383f9ccf2c7bc2a1f526158ec4';
        $url='https://api.instagram.com/oauth/access_token';

        $request_fields = array(
            'client_id' => $client_id,
            'client_secret' => $client_secret,
            'grant_type' => 'authorization_code',
            'redirect_uri' => $redirect_uri,
            'code' => $code
        );

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POST, true);
        $request_fields = http_build_query($request_fields);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $request_fields);
        $results = curl_exec($ch); 
        $results = json_decode($results,true);
        $access_token = $results['access_token'];

        echo $access_token;

        exit();
    }

?>

0 个答案:

没有答案