如何使用Dropbox.api V2加载XML文件

时间:2018-02-09 00:21:29

标签: c# xml dropbox-api

  • 我将项目从Dropbox API版本1迁移到2,当我尝试从dropbox加载xml文件时,它返回错误代码400(错误请求)。
  • 我看过documentation,但不知怎的,我仍然不明白如何正确构建第2版网址..

加载XML文件的正确V2网址是什么?

我像这样加载xml:

XmlDocument xmlDoc = new XmlDocument();
string uri = new Uri(string.Format(...)).AbsoluteUri;
xmlDoc.Load(uri);

版本1 (已弃用)

string.Format("https://content.dropboxapi.com/1/files/auto{0}?access_token={1}", svcUri, ACCESS_TOKEN)

版本2 (当前)

// What is wrong here??
string.Format("https://content.dropboxapi.com/2/files/download{0}?access_token={1}", svcUri, ACCESS_TOKEN)

提前致谢!

1 个答案:

答案 0 :(得分:1)

在您的第2版代码中,您尝试将文件路径直接放在URL路径上,并在access_token路径中传递访问令牌。它们适用于API v1,但API v2是一个不同的界面,因此那些不会在那里工作。

在API v2中,您需要更正替换is /2/files/download。这是一个"内容下载端点",因此标准的使用方式是通过带有'授权'的POST。和' Dropbox-API-Arg'头。

只是使用GET代替它,因为它似乎是你想要做的,也就是说,你可以单独使用一个URL,你可以使用URL参数documented here under "Request and response formats"

因此,要访问" /folder/filename.xml" / 2 / files / download的API调用参数为:

{"path": "/folder/filename.xml"}

对与arg网址参数一起使用的网址进行编码,以及authorization网址参数中的访问令牌信息,结果如下:

https://content.dropboxapi.com/2/files/download?authorization=Bearer%20ACCESS_TOKEN&arg=%7B%22path%22%3A%20%22%2Ffolder%2Ffilename.xml%22%7D

请务必将ACCESS_TOKEN替换为实际的访问令牌。