我目前有我的代码的上传部分工作,我将如何将其转换为将从 box 文件夹中下载相应文件的程序?
这是上传程序:
import requests
import json
#the user acces token
access_token = 'UfUNeHhv4gIxFCn5WEXHgBJwfG8gHT2o'
#the name of the file as you want it to appear in box
dst_filename = 'box_file'
#the actual file path
src_directory = 'C:\Python\cache\\'
#the name of the file to be transferred
src_filename = 'Wildlife.wmv'
#the id of the folder you want to upload to
parent_id = '0'
counter = 1
for counter in range(1, 6):
src_file = (src_directory + src_filename + '-' + str(counter))
print(src_file) …
Run Code Online (Sandbox Code Playgroud) 我开发了包含Dropbox,Google驱动器和Box云服务的android应用程序.我测试了它,一切正常.之后我签了它,我意识到调试apk大小是8.5MB而签名的apk大小是7MB.我测试了完整的应用程序,其中一切正常,除了Box云功能.我得到以下异常
11-28 12:51:14.129: E/AndroidRuntime(2702): FATAL EXCEPTION: main
11-28 12:51:14.129: E/AndroidRuntime(2702): Process: com.idealtech.mycoud, PID: 2702
11-28 12:51:14.129: E/AndroidRuntime(2702): java.lang.NoSuchFieldError: PUBLIC_ONLY
11-28 12:51:14.129: E/AndroidRuntime(2702): at java.lang.Class.getDeclaredAnnotation(Native Method)
11-28 12:51:14.129: E/AndroidRuntime(2702): at java.lang.Class.getAnnotation(Class.java:290)
11-28 12:51:14.129: E/AndroidRuntime(2702): at com.b.a.c.f.ae.<clinit>(Unknown Source)
11-28 12:51:14.129: E/AndroidRuntime(2702): at com.b.a.c.z.<clinit>(Unknown Source)
11-28 12:51:14.129: E/AndroidRuntime(2702): at com.box.boxjavalibv2.jsonparsing.BoxJSONParser.<init>(Unknown Source)
11-28 12:51:14.129: E/AndroidRuntime(2702): at com.box.boxjavalibv2.BoxClient.a(Unknown Source)
11-28 12:51:14.129: E/AndroidRuntime(2702): at com.box.boxjavalibv2.BoxClient.<init>(Unknown Source)
11-28 12:51:14.129: E/AndroidRuntime(2702): at com.box.boxjavalibv2.BoxClient.<init>(Unknown Source)
11-28 12:51:14.129: E/AndroidRuntime(2702): at com.box.boxandroidlibv2.BoxAndroidClient.<init>(Unknown Source)
11-28 12:51:14.129: E/AndroidRuntime(2702): at com.box.boxandroidlibv2.activities.OAuthActivity.a(Unknown Source)
11-28 12:51:14.129: …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Box API 将文件上传到 box.com。根据文档,curl 请求必须如下所示:
curl https://upload.box.com/api/2.0/files/content \
-H "Authorization: Bearer ACCESS_TOKEN" -X POST \
-F attributes='{"name":nameOftheFile, "parent":{"id":parentId}}' \
-F file=@file
Run Code Online (Sandbox Code Playgroud)
这是我所做的:
$token = "......";
$url = https://upload.box.com/api/2.0/files/content;
$file_upload;
foreach ($_FILES['file']['name'] as $position => $file) {
$file_upload = $_FILES['file']['tmp_name'][$position];
}
$json = json_encode(array('name' => $file ,array('parent' => array('id' => 0))));
$attrs = array('attributes' => $json,'file'=>'@'.$file_upload);
$this->post($url,($attrs));
// Post function
function post($url,$fields){
try {
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer '.$this->token
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, …
Run Code Online (Sandbox Code Playgroud) 我正在尝试开始使用Box.com SDK,我有几个问题.
from boxsdk import OAuth2
oauth = OAuth2(
client_id='YOUR_CLIENT_ID',
client_secret='YOUR_CLIENT_SECRET',
store_tokens=your_store_tokens_callback_method,
)
auth_url, csrf_token = oauth.get_authorization_url('http://YOUR_REDIRECT_URL')
def store_tokens(access_token, refresh_token):
# store the tokens at secure storage (e.g. Keychain)
Run Code Online (Sandbox Code Playgroud)
1)什么是重定向网址以及如何使用它?我是否需要运行服务器才能使用它?
2)我在store_tokens方法中需要什么样的代码?
我正在尝试使用以下代码通过 API从Box.com下载文件。
<cfhttp url="https://api.box.com/2.0/files/(FILE_ID)/content/" method="GET" redirect="true" >
<cfhttpparam type="header" name="Authorization" value="Bearer (DEVELOPER_TOKEN)">
</cfhttp>
Run Code Online (Sandbox Code Playgroud)
根据文档,它应该302 Found
作为响应返回。并重定向到 dl.boxcloud.com 进行下载。但我得到的200
回应。
不知道为什么我得到 200 作为回应。我需要通过 API 调用下载文件。我错过了什么吗?