0
votes

I am managed to get tokens and using token to get the content from box.com site. I seen with other site like drop box,smug mug gives many versions of URL of images but here I am not seeing when I pull using the below command

https://www.box.com/api/2.0/folders/0?access_token= and the result is below.

I want to know the path of an image 20131228_181031.jpg in below data, I want to pull the image using php file_getcontent command for which I need image path.

{
  "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 protected]"
  },
  "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"
      }
    ]
  }
}
1

1 Answers

1
votes

On the Box API, when requesting a file, you do not need to know the folder it is in and so you do not need to build the path. You just make the request with the file id and include your access token in the header. For more info see the getting started docs here.

A quick example using file_get_contents is below:

<?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);

The $fileId is the "id" field in the JSON data you provided, so for the file you need it would be 12673472942.

Hope that helps.