我正在尝试使用Box.com的API开发一个允许创建文件夹的快速应用程序。我无法连接到他们的API,并且对于oAUTH2,API和诸如此类的东西都是新手。我试过按照这些指南:
http://developers.box.com/oauth/
http://developers.box.com/docs/#folders-create-a-new-folder
Box.com文档说
response_type:端点是否返回授权码。对于Web应用程序,应使用代码值。
client_id:您在初始设置中获取的client_id。
redirect_uri:将重定向响应的HTTPS URI或自定义URL方案。如果已使用Box注册重定向URI,则为可选。
state:您选择的任意字符串,将包含在对您的应用程序的响应中。 Box建议您使用防伪状态令牌来防止对用户的CSRF攻击
因此,示例GET请求可能如下所示:
获取https://www.box.com/api/oauth2/authorize?response_type=code&client_id=MY_CLIENT_ID&state=security_token%3DKnhMJatFipTAnM0nHlZA
我有他们的开发帐户,这是我的基本jquery不工作..
$.ajax({
//The URL to process the request
url : 'https://www.box.com/api/oauth2/authorize',
type : 'GET',
data : {
response_type : 'code',
client_id : 'm025a55gtov17txux1v2vbzjjhph2b6n'
},
success: function( resp ) {
console.log( resp.people );
},
error: function( req, status, err ) {
console.log( 'something went wrong', status, err );}
});
任何人都可以指出我如何做到这一点的方向?我很难过。
我确实找到了一种连接到他们的API并获得令牌的方法,但是当我尝试向他们的服务器发送POST请求以创建文件夹(我的应用程序的主要目标)时,我收到了一个CORS错误。这是我如何权衡令牌的代码
authorizeUser = function(){
var results = $.ajax({
// The URL to process the request
url : 'https://www.box.com/api/oauth2/token',
type : 'POST',
data : {
grant_type : 'authorization_code',
code : data.boxAuthorizationCode,
client_id : data.clientId,
client_secret : data.clientSecret
},
beforeSend: function (xhr) {
xhr.setRequestHeader("Authorization", "Bearer $token")
},
dataType: "json",
success: function(response) {
//console.log(response);
console.log(response.access_token);
data.access_token = response.access_token;
tokenGranted();
}
});
return results.responseText;
},