使用其他查询参数时,Instagram重定向URI与原始重定向URI不匹配

Jan*_*tia 5 php wordpress oauth instagram

我正在为WordPress开发插件,其中用户单击“在Instagram上登录”按钮以授权我的Instagram应用。授权后,该插件基本上只会从用户那里获取最新的Instagram照片,并通过小部件进行显示。

这是我的插件如何工作的分步说明:

  1. 用户单击WordPress设置页面上的“在Instagram上登录”。
  2. 用户将被带到Instagram的“授权”屏幕(登录屏幕)
  3. 用户成功验证并批准了我的应用。
  4. Instagram将用户重定向到我的重定向URI
  5. 文件“ instagram-api-redirect.php”将同时获得“ code”和“ return_uri”参数。其中“代码”用于请求“访问令牌”。
  6. 它将与“访问令牌”一起重定向回WordPress设置页面。
  7. 该插件将“访问令牌”存储到数据库中以用于认证请求。

我遇到的问题是,我在步骤5上收到了一条错误消息:“重定向URI与原始重定向URI不匹配”。当我从重定向URI中删除“ return_uri”查询参数时,它工作正常。

一些细节可能会有所帮助:

这是我的应用程序中的重定向URI

http:// mysite.com/plugins/pulp_instagram/instagram-api-redirect.php

这是我发送到Instagram的“ / authorize”的重定向URI

http:// mysite.com/plugins/pulp_instagram/instagram-api-redirect.php?return_uri=http:// localhost / instagram-app

这是我要发送到Instagram的“ / authorize”的完整授权URL :

https://api.instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=http:// mysite.com/plugins/pulp_instagram/instagram-api-redirect.php?return_uri=http:// localhost / instagram -app&response_type =代码

这是URL响应:

http:// mysite.com/plugins/pulp_instagram/instagram-api-redirect.php?return_uri=http:// localhost / instagram-app&code = 557d15dacd0d40459edf70aa159476de

这是“ instagram-api-redirect.php”文件的完整代码:

<?php 

// the redirect uri
$return_uri = $_GET['return_uri'];

require 'instagram.class.php';

// Initialize class
$instagram = new Instagram(array(
  'apiKey'      => 'CLIENT-ID',
  'apiSecret'   => 'CLIENT-SECRET',
  'apiCallback' => 'http://mysite.com/plugins/pulp_instagram/instagram-api-redirect.php'
));

// Receive OAuth code parameter
$code = $_GET['code'];

// Check whether the user has granted access
if (true === isset($code)) {

    // Receive OAuth token object
    $data = $instagram->getOAuthToken($code);
    print_r($data); 
} else {

  // Check whether an error occurred
  if (true === isset($_GET['error'])) {
    echo 'An error occurred: '.$_GET['error_description'];
  }

}
?>
Run Code Online (Sandbox Code Playgroud)

另外,我正在使用来自cosenary的“ Instagram PHP API”类(instagram.class.php)。

提前致谢!