1

按照 Box.com View API 的说明创建会话

curl https://view-api.box.com/1/sessions \
-H "Authorization: Token YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"document_id": "ABC123"}' \
-X POST

我使用 RestSharp 编写代码:

var client = new RestClient("https://view-api.box.com/1/sessions");
            RestRequest request = new RestRequest(Method.POST);
            request.RequestFormat = DataFormat.Json;
            request.AddHeader("Authorization", "Token r6bcsuizpt18hwf9fsq7l15oj7fts12x");
            request.AddHeader("Content-type", "application/json");

            request.AddBody(new { document_id = "19877746783" });
            var response = client.Execute<HttpResponseMessage>(request).Content;

但我得到了回应:

{"message": "Bad request", "type": "error", "details": [{"field": "document_id", "message": "Ensure this value has at least 32 characters (it has 11)."}], "request_id": "1e5ea09a373546c283d676d5c890cecb"}

而 document_id 19877746783 是完全正确的。

我不知道我为什么收到这条消息。谢谢

4

1 回答 1

0

ID 看起来不像是由 View API 生成的(它们是 32 个字符)。唯一适用于 View API 的 ID 来自使用POST /documents方法直接上传到 View API 的文档,即您将调用此 API

curl https://view-api.box.com/1/documents \
-H "Authorization: Token YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"url": "URL_TO_DOCUMENT"}' \
-X POST

并将收到此回复

{
    "type": "document",
    "id": "DOCUMENT_ID",
    "status": "done",
    "name": "",
    "created_at": "2013-08-30T00:17:37Z"
}

您需要使用DOCUMENT_ID上述方法创建会话。

于 2014-08-13T16:51:51.790 回答