繁体   English   中英

Instagram 基本显示 API - 此授权码已被使用

[英]Instagram Basic Display API - This authorization code has been used

我需要允许我平台的用户通过 Instagram 基本显示 API 链接他们的 Instagram 帐户。 当我调用获取代码以交换访问令牌时,它始终是相同的,并导致下一步出错。

这些是我正在执行的步骤,遵循这个官方指南

  1. 使用以下参数获取请求: https://api.instagram.com/oauth/authorize?client_id=XXXXX&redirect_uri=XXXXX&scope=user_profile&response_type=code
  2. 通过 PHP 中的 cURL 向https://api.instagram.com/oauth/access_token POST 请求,将参数传递为下面的第二个代码片段
  3. 使用'https://graph.instagram.com/'. $result->user_id. '?fields=username&access_token='. $result->access_token 'https://graph.instagram.com/'. $result->user_id. '?fields=username&access_token='. $result->access_token 'https://graph.instagram.com/'. $result->user_id. '?fields=username&access_token='. $result->access_token通过 PHP 中的 cURL

该过程在 1 和 2 之间失败,因为即使我使用不同的帐户进行了多次尝试,第一步总是返回相同的代码

这是代码请求的 HTML 表格。 成功打开 Instagram 登录页面:

<a class="insta-con" href="https://api.instagram.com/oauth/authorize?client_id=XXXXX&redirect_uri=XXXXX&scope=user_profile&response_type=code">
   <img src="assets/images/instalogo.png" alt="Connetti a Instagram">
   <p>Connect to Instagram</p>
</a>

登录表单总是返回相同的代码,也使用不同的帐户,导致错误{"error_type": "OAuthException", "code": 400, "error_message": "This authorization code has been used"}在下一个请求中:

$fields = array(
    'client_id'     => 'XXXXXX',
    'client_secret' => 'XXXXXXXXX',
    'grant_type'    => 'authorization_code',
    'redirect_uri'  => 'https://www.XXXXXXX.it/connect.php',
    'code'          => $_GET['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);
curl_setopt($ch, CURLOPT_VERBOSE,true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0');
$result = curl_exec($ch);
if(curl_errno($ch)) {
    echo 'Curl error: ' . curl_error($ch);
}
curl_close($ch);
$result = json_decode($result, true);

所以我的问题是:尽管帐户不同,为什么我总是得到相同的代码?

我通过验证业务或使用Facebook开发者控制台中的个人验证解决了这个问题。

在使用 API 之前,您需要验证您的身份,单击设置 > 基本设置,然后滚动到个人验证企业验证并完成所有步骤。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM