【发布时间】:2020-06-13 19:55:15
【问题描述】:
我想将 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,但我仍然遇到同样的错误。
我不确定是什么原因。
【问题讨论】:
标签: php instagram instagram-api