我设法获取令牌并使用令牌从box.com网站获取内容。我看到其他网站像丢弃框,自鸣得意的杯子提供了许多版本的图像的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"
}
]
}
}
答案 0 :(得分:1)
在Box API上,当您请求文件时,您不需要知道它所在的文件夹,因此您不需要构建路径。您只需使用文件ID发出请求,并在标头中包含您的访问令牌。有关详细信息,请参阅入门文档here。
使用file_get_contents
的快速示例如下:
<?php
$fileId = 12673472942;
$accessToken = 'YOURACCESSTOKENGOESHERE';
$sBox = stream_context_create(array(
'http'=> array(
'header' => "Authorization: Bearer $accessToken\r\n"
)
));
$fileData = file_get_contents(
"https://api.box.com/2.0/files/$fileId/content",
false,
$sBox
);
var_dump($fileData);
$fileId
是您提供的JSON数据中的"id"
字段,因此对于您需要的文件,它将是12673472942
。
希望有所帮助。