Box.net Api未返回图像的路径



我设法获得令牌,并使用令牌从box.com网站获取内容。我看到了其他网站,比如Dropbox,自鸣得意的马克杯提供了许多版本的图像URL,但在这里我没有看到,当我使用下面的命令拉

https://www.box.com/api/2.0/folders/0?access_token=结果如下。

我想知道下面数据中图像20131228_181031.jpg的路径,我想使用php file_getcontent命令提取图像,我需要图像路径。

{
"type": "folder",
"id": "0",
"sequence_id": null,
"etag": null,
"name": "All Files",
"created_at": null,
"modified_at": null,
"description": "",
"size": 9985219,
"path_collection": {
"total_count": 0,
"entries": []
},
"created_by": {
"type": "user",
"id": "",
"name": "",
"login": ""
},
"modified_by": {
"type": "user",
"id": "207866808",
"name": "praveen",
"login": " my id"
},
"trashed_at": null,
"purged_at": null,
"content_created_at": null,
"content_modified_at": null,
"owned_by": {
"type": "user",
"id": "207866808",
"name": "Chandler",
"login": "email@tbl.com"
},
"shared_link": null,
"folder_upload_email": null,
"parent": null,
"item_status": "active",
"item_collection": {
"total_count": 5,
"entries": [
{
"type": "file",
"id": "12673472942",
"sequence_id": "0",
"etag": "0",
"sha1": "a43eceb5de8ea1334aa545c95e92d7527f7bf163",
"name": "20131228_181031.jpg"
},
{
"type": "file",
"id": "12673467202",
"sequence_id": "0",
"etag": "0",
"sha1": "dfce2896cd97856fbe2755ec5b7e344103181e87",
"name": "20131228_181034.jpg"
},
{
"type": "file",
"id": "12673477676",
"sequence_id": "0",
"etag": "0",
"sha1": "dee70d192fc6bfec538d5581f8460005d7a79155",
"name": "20131228_181938.jpg"
},
{
"type": "file",
"id": "12673481562",
"sequence_id": "0",
"etag": "0",
"sha1": "a07e7c970ed0aa7fdab955aaad0d4e245d1595cd",
"name": "20131228_181943.jpg"
},
{
"type": "file",
"id": "12673486582",
"sequence_id": "0",
"etag": "0",
"sha1": "156446b911a22604b2a0c032888b4d7a6b6a3bfd",
"name": "20131228_181957.jpg"
}
],
"offset": 0,
"limit": 100,
"order": [
{
"by": "type",
"direction": "ASC"
},
{
"by": "name",
"direction": "ASC"
}
]
}
}

在Box API上,当请求文件时,您不需要知道它所在的文件夹,因此不需要构建路径。您只需使用文件id发出请求,并在标头中包含您的访问令牌。有关更多信息,请参阅此处的入门文档。

使用file_get_contents的一个快速示例如下:

<?php
$fileId = 12673472942;
$accessToken = 'YOURACCESSTOKENGOESHERE';
$sBox = stream_context_create(array(
'http'=> array(
'header' => "Authorization: Bearer $accessTokenrn" 
)
));
$fileData = file_get_contents(
"https://api.box.com/2.0/files/$fileId/content", 
false, 
$sBox
);
var_dump($fileData);

$fileId是您提供的JSON数据中的"id"字段,因此对于您需要的文件,它将是12673472942

希望能有所帮助。

最新更新