php - Instagram 基本显示 API OAuth 错误 : code 400, invalid_redirect_uri

标签 php instagram instagram-api

我想将 Instagram Basic Display API 与网站连接,以显示某个用户的帖子。但是,当尝试验证用户(我自己,出于测试目的)时,我收到此错误:

{"error_type": "OAuthException", "code": 400, "error_message": "Invalid redirect_uri"}

这是我用于请求的 PHP 代码:

require_once 'ig_defines.php';

Class instagram_basic_display_api {

    private $_appId = INSTAGRAM_APP_ID;
    private $_appSecret = INSTAGRAM_APP_SECRET;
    private $_redirectUrl = INSTAGRAM_APP_REDIRECT_URI;
    private $_getCode = '';
    private $_apiBaseUrl = 'https://api.instagram.com/';

    public $authorizationUrl = '';

    // called on class init
    function __construct( $params ) {

        // save instagram code
        $this->_getCode = $params['get_code'];

        // get an access token (code will follow)

        // get authorization url
        $this->_setAuthorizationUrl();
    } 

    private function _setAuthorizationUrl() {
        $getVars = array(
            'app_id' => $this->_appId,
            'redirect_uri' => $this->_redirectUrl,
            'scope' => 'user_profile,user_media',
            'response_type' => 'code'
        );
        // create url
        $this->authorizationUrl = $this->_apiBaseUrl . 'oauth/authorize?' . http_build_query( $getVars );
    }
}

private $_redirectUrl = INSTAGRAM_APP_REDIRECT_URI; 为建议的 “http://google.com/” in this post 。我在 facebook 开发者工具 Instagram API 设置中的 OAuth 重定向 URI 也是 "http://google.com/"

为了进行测试,我使用我的测试网络空间。 URL 类似于 http://mytestwebspace.de/instagram/news_ig_test.php。如您所见,它没有 SSL。不过,最后一页即将到来。缺少 SSL 会成为问题吗?

编辑:我忘了添加,我之前确实尝试过使用 http://mytestwebspace.de/instagram/news_ig_test.php 作为redirectUrl,但我仍然遇到相同的错误。

我不确定原因是什么。

最佳答案

我可以确认,需要 SSL。使用 https://mytestwebspace.de/etc... 时,身份验证工作得很好。 (虽然这并不奇怪,但我没想到解决方案如此简单,因此我开了一个线程。)

关于php - Instagram 基本显示 API OAuth 错误 : code 400, invalid_redirect_uri,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60473276/

相关文章:

android - 如何在像 instagram 这样的圆形 ImageView 周围设置边框?

instagram - 如何计算 Instagram 媒体用户喜欢的数量?

php - 如何嵌入 instagram 个人资料?

php - 自动提交表单 (cURL)

php - SQL_BIG_SELECTS,优化我的查询

ios - 从Instagram获取照片

javascript - 如何在不使用第三方小部件的情况下将我最近的 Instagram 帖子嵌入到 html 中?

php - MySQL:获取添加了 x 小时的行

javascript - Dreamweaver 不断将外部 CSS 文件与本地服务器上的本地 CSS 一起拉取

Instagram 实时 api - 设法仅获取最后上传的图像