2013-12-16 44 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標題。