I know this was asked long back, but still I believe many people are searching for the way to do it.
Please check Box SDK for more details.
And I'm using OAuth2.0 - Custom App. You can create the credentials from the developer console.
Here's the code.
from boxsdk import OAuth2, Client
#from boxsdk import Folder
auth = OAuth2(
client_id='fbxxxxxxxxxxxxxxxxxxxxxxxxxxxxx9',
client_secret='bPxxxxxxxxxxxxxxxxxxxxxxxxx4Or',
access_token='QExxxxxxxxxxxxxxxxxxxxxxxxxxwt',
)
client = Client(auth)
root_folder = client.root_folder().get()
items = root_folder.get_items()
for item in items:
print('{0} {1} is named "{2}"'.format(item.type.capitalize(), item.id, item.name))
with open(item.name, 'wb') as open_file:
client.file(item.id).download_to(open_file)
open_file.close()
Hope this will help you. Thanks to the Python boxsdk 2.0.0 Doc.
Answer from Parvathirajan Natarajan on Stack OverflowI know this was asked long back, but still I believe many people are searching for the way to do it.
Please check Box SDK for more details.
And I'm using OAuth2.0 - Custom App. You can create the credentials from the developer console.
Here's the code.
from boxsdk import OAuth2, Client
#from boxsdk import Folder
auth = OAuth2(
client_id='fbxxxxxxxxxxxxxxxxxxxxxxxxxxxxx9',
client_secret='bPxxxxxxxxxxxxxxxxxxxxxxxxx4Or',
access_token='QExxxxxxxxxxxxxxxxxxxxxxxxxxwt',
)
client = Client(auth)
root_folder = client.root_folder().get()
items = root_folder.get_items()
for item in items:
print('{0} {1} is named "{2}"'.format(item.type.capitalize(), item.id, item.name))
with open(item.name, 'wb') as open_file:
client.file(item.id).download_to(open_file)
open_file.close()
Hope this will help you. Thanks to the Python boxsdk 2.0.0 Doc.
Assume you are getting your authorization correct you can download file by adding few lines to code to your Existing code. This will copy data from box file to local file here name is FileFromBox.xlx
with open('FileFromBox.xls', 'wb') as open_file:
client.file('FileId_of_box_file').download_to(open_file)
open_file.close()
It looks like we're experiencing a minor bug on our end that's preventing downloads. If you use 'https://www.box.com/' instead of 'https://api.box.com/' the download should work. We're working on fixing the bug right now, however!
I'm not sure if you are still interested in the answer, but this code works well for me:
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);
}
Get metadata of shared Box link:
shared_folder = client.get_shared_item("https://app.box.com/s/0123456789abcdef0123456789abcdef")
Loop through each item inside the folder and download each file using boxsdk.object.file.File.content or boxsdk.object.file.File.download_to:
for item in shared_folder.get_items(limit=1000):
if item.type == 'file':
# Get file contents into memory
file_contents = client.file(file_id=item.id).content()
# Or download to file
client.file(file_id=item.id).download_to(item.name)
You can use the method that gives you the direct URL:
download_url = client.file(file_id='SOME_FILE_ID').get_shared_link_download_url()
And then you can use urlib to download it to your local computer:
import urllib
urllib.urlretrieve (download_url , your_local_file_name)
Could it solve your problem?