我正在尝试使用他们的服务器端/显式流程从Instagram API获取访问令牌。
当用户成功认证并授权我的应用程序时,Instagram会使用代码参数将用户重定向到我的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代码)。
有任何想法吗?预先非常感谢您的帮助!
使用服务器端显式流时,必须对oauth使用服务器端代码,由于跨域请求,浏览器已将其阻止。如果您只想使用javascript,则使用客户端隐式流
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句