我想将 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/