【发布时间】:2013-12-21 08:55:12
【问题描述】:
上下文
我正在尝试使用他们的server-side/explicit flow 从 Instagram API 获取 访问令牌。
当用户成功验证并授权我的应用程序时,Instagram 会使用 code 参数将用户重定向到我的 redirect_uri。 获得此代码后,我将尝试调用 Instagram API 以获取 access_token。
问题
我成功获得此代码,但为了进行此交换,我必须将代码连同一些应用识别参数一起发布到他们的 access_token 端点:
$.ajax({
type: 'POST',
url: 'https://api.instagram.com/oauth/access_token',
// Disable credentials as they were enabled by default
xhrFields: {
withCredentials: false
},
crossDomain: true,
data: {
client_id: client_id,
client_secret: client_secret,
grant_type: 'authorization_code',
redirect_uri: callback_http,
code: token
},
}).always(function(res) {
console.log('Res from Instagram API', res);
});
问题是我遇到 Access-Control-Allow-Origin 问题:
XMLHttpRequest cannot load https://api.instagram.com/oauth/access_token.
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin '[here is my callback_http]' is therefore not allowed access.
我尝试使用 dataType: 'jsonp' 作为 Ajax 调用的参数,但没有成功(401 代码)。
有什么想法吗?非常感谢您的帮助!
【问题讨论】:
-
服务器端意味着它必须从你的服务器访问:)
标签: javascript ajax instagram access-token same-origin-policy