2012-05-01 91 views
1

試圖使用新API下載文件。但是,我得到一個錯誤(NOTFOUND)Box API 2.0下載文件

隨着舊的API,我下載罰款:

wcGetFile.DownloadStringAsync(new Uri("https://www.box.net/api/1.0/download/" + auth_token + "/2111821875")); 

有了新的API,這是我的代碼:

wcGetFile.Headers[HttpRequestHeader.Authorization] = "BoxAuth api_key=" + api_key + "&auth_token=" + auth_token; 
     wcGetFile.DownloadStringAsync(new Uri("https://api.box.com/2.0/files/2111821875/data")); 

該文件不存在,因爲如果我從我的電話結束時刪除「數據」我得到的文件信息沒有錯誤。

wcGetFile.Headers[HttpRequestHeader.Authorization] = "BoxAuth api_key=" + api_key + "&auth_token=" + auth_token; 
     wcGetFile.DownloadStringAsync(new Uri("https://api.box.com/2.0/files/2111821875")); 

根據文檔,信息和實際文件的唯一區別是url的'data'部分。但這似乎並不適用於我。

回答

1

看起來我們正在遇到一個小問題,即阻止下載。如果您使用'https://www.box.com/'而不是'https://api.box.com/',則下載應該可以正常工作。但是,我們正在努力修復此錯誤!

+0

我已嘗試改變,但我得到了同樣的錯誤。 – zawisza

0

我不知道你是否仍然有興趣在回答,但是這個代碼很適合我:

public static Task DownloadFile(string fileId, string location, string authToken) { 
    var auth = string.Format("Authorization: BoxAuth api_key={0}&auth_token={1}", ApiKey, authToken); 
    var uri = new Uri(string.Format("https://api.box.com/2.0/files/{0}/data", fileId)); 

    var client = new WebClient(); 
    client.Headers.Add(auth); 
    return client.DownloadFileTaskAsync(uri, location); 
}