DropBox API使用Curl和Oauth 2将文件上载到DropBox的示例

DropBox API使用Curl和Oauth 2将文件上载到DropBox的示例,curl,oauth-2.0,dropbox,Curl,Oauth 2.0,Dropbox,我到处都在搜索,没有找到一个合适的例子,也没有足够的经验通过文档进行分类。有没有比我更了解的人能告诉我如何为OAUTH 2生成CURL命令?我只需要OAUTH 2密钥吗?我正在看一个应用程序密钥、应用程序密钥和oauth 2。如果重要的话,我会在perl脚本中使用它 我找到的最接近的代码是: curl --request PUT --header "Content-Length: `ls -la jonathan.txt | awk '{ print $5}'`" --header

我到处都在搜索,没有找到一个合适的例子,也没有足够的经验通过文档进行分类。有没有比我更了解的人能告诉我如何为OAUTH 2生成CURL命令?我只需要OAUTH 2密钥吗?我正在看一个应用程序密钥、应用程序密钥和oauth 2。如果重要的话,我会在perl脚本中使用它

我找到的最接近的代码是:

 curl --request PUT --header "Content-Length: `ls -la jonathan.txt | awk '{ print $5}'`" --header         
 "Content-Type: multipart/mixed" --data-binary "@jonathan.txt" "https://api-    
 content.dropbox.com/1/files_put/dropbox/jonathan.txt?access_token=ABCDEF"
但我认为这不是OAUTH 2?

您需要一个帐户访问令牌。(这通常通过OAuth流获得,但您也可以通过单击Dropbox应用程序页面上的“生成”按钮为自己的帐户获得一个。请参阅。)

一旦有了访问令牌,curl命令应该可以工作,尽管我更喜欢
--header“Authorization:Bearer abc123xyz”
而不是将访问令牌放入查询参数中。此外,请删除
内容类型:multipart/mixed
,因为这不是您要发送的内容


我还建议使用“自动”而不是“dropbox”,因为无论应用程序类型如何,它总是做正确的事情。

如果您有访问令牌(通过应用程序控制台创建):

curl-H“授权:承载”https://api-content.dropbox.com/1/files_put/auto/ -T

以下是通过CURL请求将文件上传到dropbox的工作代码

curl -X POST https://content.dropboxapi.com/2/files/upload \
  --header "Authorization: Bearer <your token>" \
  --header "Dropbox-API-Arg: {\"path\": \"/file_path.txt\",\"mode\": \"add\",\"autorename\": true,\"mute\": false}" \
  --header "Content-Type: application/octet-stream" \
  --data-binary "@file_path.txt"
curl-X POSThttps://content.dropboxapi.com/2/files/upload \
--标题“授权:持票人”\
--标题“Dropbox API参数:{\'path\':\”/file\u path.txt\,\“mode\:\“add\”,“autorename\”:true,\“mute\”:false}”\
--标题“内容类型:应用程序/八位字节流”\
--数据二进制“@file_path.txt”

谢谢。我希望两个都能通过,但是由于汉斯通过列出代码使它变得更简单了,所以我把代码交给了他。不过,我非常感谢您提供的额外信息。看起来/1/files\u put/auto不再可用。尝试/2/files/upload:
curl-xposthttps://content.dropboxapi.com/2/files/upload --header“Authorization:Bearer”--header“Dropbox API参数:{“path\”:“/homotation/math/matrix.txt\”,“mode\”:“add\”,“autorename\”:true,\“mute\”:false}”--header“内容类型:应用程序/八位字节流”--数据二进制@local u file.txt
curl -X POST https://content.dropboxapi.com/2/files/upload \
  --header "Authorization: Bearer <your token>" \
  --header "Dropbox-API-Arg: {\"path\": \"/file_path.txt\",\"mode\": \"add\",\"autorename\": true,\"mute\": false}" \
  --header "Content-Type: application/octet-stream" \
  --data-binary "@file_path.txt"