2013-12-16 43 views
1

你好,我是用箱API来整合他们给刚刚卷曲获得访问令牌 这是遵循发布采购信息

curl https://www.box.com/api/oauth2/token \ 
-d 'grant_type=authorization_code&code={your_code}&client_id={your_client_id}&client_secret={your_client_secret}' \ 
-X POST 

我想使用jQuery Ajax请求我一定要得到的访问令牌累了我这样的代码如下:

var data2= '{"grant_type":"authorization_code", "client_id":"READACTED" ,"client_secret":"Redacted" ,"code" :"'+code+'"}'; 
var data1 = JSON.parse(data2); 

$.ajax({ 
        type: 'POST', 
        url: "https://www.box.com/api/oauth2/token", 
        data: data1, 
        success: function(json) { 
         console.log(e); 
         alert("success"+json); 
        }, 
        error: function(e) { 
         console.log(e) 
         alert("Failure"+ JSON.stringify(e)); 

        } 
       }); 

我现在面临的问题与此请求,因为它给了我在浏览器控制台错误:

XMLHttpRequest cannot load https://www.box.com/api/oauth2/token. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. 

请告诉我我错在哪里,它和Postman客户端正常工作。

+0

你想做什么?你有什么尝试? –

+0

@RocketHazmat请现在检查我已经提到更多详细信息 –

+0

您被[相同来源政策]阻止(http://en.wikipedia.org/wiki/Same-origin_policy)。您无法直接从JavaScript访问box.com API。 –

回答

0

为了通过相同来源的政策,您需要联系Box支持团队。您可以发送电子邮件至[email protected],也可以按照右下角框内网页上的“Box Community”链接进行操作。

支持小组会要求您在CORS标头中输入您想要使用的起始URL或URL(Box不允许通配符起源)。他们还需要知道您的应用程序名称或API Key以查找您的应用程序并为您设置CORS标题。