donglong7338 2016-07-13 10:44
浏览 96

使用PHP进行Instagram身份验证

Hello fellow developers,

I searched everywhere and it seems like this question remain unresolved, some appears to solve this by using proxy servers or changing their IP address, which didn't work in my case. Since Instagram doesn't have an official PHP or JavaScript SDK, I need to ask this question here.

When I attempt to make a Oauth Call to Instagram by retrieved token it will return an error message below:

{"code": 400, "error_type": "OAuthException", "error_message": "Matching code was not found or was already used."}

I have included by code below for your observation:

Getting Token

private function getLoginURL($scopes = array("basic")) {
    return self::API_OAUTH_URL."/?client_id=".self::CLIENT_ID."&redirect_uri=".self::REDIRECT_URI."&scope=".implode("+", $scopes)."&response_type=code";
}

Authentication (Oauth 2.0)

private function auth() {
    $api_data = array(
        'client_id'     => self::CLIENT_ID,
        'client_secret' => self::CLIENT_SECRET,
        'grant_type'    => 'authorization_code',
        'redirect_uri'  => urlencode(self::TOKEN_URL),
        'code'          => self::TOKEN
    );

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, self::TOKEN_URL);
    curl_setopt($ch, CURLOPT_POST, count($api_data));
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($api_data));
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_TIMEOUT, 90);

    $json_data = curl_exec($ch);
    curl_close($ch);
    //return json_decode($json_data, true);
    return $json_data;
}

Could someone help me out :(

  • 写回答

1条回答 默认 最新

  • donglu7286 2016-07-14 17:08
    关注

    Problem: Your response type is code.

    1. Due to new changes in Instagram's API, you will need your response type to be token.
    2. This may require some reworking of your existing code.

    3. While using token, the scope specification comes afterwards.

      private function getLoginURL($scopes = array("basic")) {
          return self::API_OAUTH_URL."/?client_id=".self::CLIENT_ID."&redirect_uri=".self::REDIRECT_URI."&response_type=token&scope=".implode("+", $scopes);
      }
      
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!