Zinc newbie question: How to get file metadata from Dropbox
Hi! To download a file from Dropbox is easy: ZnClient new https; host: 'content.dropboxapi.com'; addPath: '2'; addPath: 'files'; addPath: 'download'; headerAt: 'Authorization' put: 'Bearer <my generated access token>'; headerAt: 'Dropbox-API-Arg' put: '{"path": "/demo.txt"}' ;get. But I cannot figure out how to get file metadata (https://www.dropbox.com/developers/documentation/http/documentation#files-ge...). If I try the following (ZnClient new https; host: 'api.dropboxapi.com'; addPath: '2'; addPath: 'files'; addPath: 'get_metadata'; headerAt: 'Authorization' put: 'Bearer QfCCKhxI-HwAAAAAAAAGdeT916yqY4tkX3EN6EW2S3EMxYyv5Xky9LeCxuGi8_o7'; headerAt: 'Content-Type' put: 'application/json'; formAt: 'path' put: 'demo.txt'; post). I get the error message from Dropbox: Error in call to API function "files/get_metadata": Bad HTTP "Content-Type" header: "application/x-www-form-urlencoded". Expecting one of "application/json", "application/json; charset=utf-8", "text/plain; charset=dropbox-cors-hack". Probably I am using ZnClient wrongly. Johannes
On 20 Jul 2017, at 19:57, Johannes Brauer <brauer@nordakademie.de> wrote:
Hi!
To download a file from Dropbox is easy:
ZnClient new https; host: 'content.dropboxapi.com'; addPath: '2'; addPath: 'files'; addPath: 'download'; headerAt: 'Authorization' put: 'Bearer <my generated access token>'; headerAt: 'Dropbox-API-Arg' put: '{"path": "/demo.txt"}' ;get.
But I cannot figure out how to get file metadata (https://www.dropbox.com/developers/documentation/http/documentation#files-ge...).
If I try the following
(ZnClient new https; host: 'api.dropboxapi.com'; addPath: '2'; addPath: 'files'; addPath: 'get_metadata'; headerAt: 'Authorization' put: 'Bearer QfCCKhxI-HwAAAAAAAAGdeT916yqY4tkX3EN6EW2S3EMxYyv5Xky9LeCxuGi8_o7'; headerAt: 'Content-Type' put: 'application/json'; formAt: 'path' put: 'demo.txt'; post).
I get the error message from Dropbox:
Error in call to API function "files/get_metadata": Bad HTTP "Content-Type" header: "application/x-www-form-urlencoded". Expecting one of "application/json", "application/json; charset=utf-8", "text/plain; charset=dropbox-cors-hack".
By using #formAt:put: you implicitly create a ZnApplicationFormUrlEncodedEntity instance, this is not what you want/need. This would POST proper JSON: ZnClient new https; host: 'api.dropboxapi.com'; addPath: '2'; addPath: 'files'; addPath: 'get_metadata'; headerAt: 'Authorization' put: 'Bearer QfCCKhxI-HwAAAAAAAAGdeT916yqY4tkX3EN6EW2S3EMxYyv5Xky9LeCxuGi8_o7'; entity: (ZnEntity with: (STONJSON toString: { #path->'demo.txt' } asDictionary) type: ZnMimeType applicationJson); post. Does that work ?
Probably I am using ZnClient wrongly.
Johannes
Sven Van Caekenberghe-2 wrote
On 20 Jul 2017, at 19:57, Johannes Brauer <
brauer@
> wrote:
Hi!
To download a file from Dropbox is easy:
ZnClient new https; host: 'content.dropboxapi.com'; addPath: '2'; addPath: 'files'; addPath: 'download'; headerAt: 'Authorization' put: 'Bearer
<my generated access token> ';
headerAt: 'Dropbox-API-Arg' put: '{"path": "/demo.txt"}' ;get.
But I cannot figure out how to get file metadata (https://www.dropbox.com/developers/documentation/http/documentation#files-ge...).
If I try the following
(ZnClient new https; host: 'api.dropboxapi.com'; addPath: '2'; addPath: 'files'; addPath: 'get_metadata'; headerAt: 'Authorization' put: 'Bearer QfCCKhxI-HwAAAAAAAAGdeT916yqY4tkX3EN6EW2S3EMxYyv5Xky9LeCxuGi8_o7'; headerAt: 'Content-Type' put: 'application/json'; formAt: 'path' put: 'demo.txt'; post).
I get the error message from Dropbox:
Error in call to API function "files/get_metadata": Bad HTTP "Content-Type" header: "application/x-www-form-urlencoded". Expecting one of "application/json", "application/json; charset=utf-8", "text/plain; charset=dropbox-cors-hack".
By using #formAt:put: you implicitly create a ZnApplicationFormUrlEncodedEntity instance, this is not what you want/need. This would POST proper JSON:
ZnClient new https; host: 'api.dropboxapi.com'; addPath: '2'; addPath: 'files'; addPath: 'get_metadata'; headerAt: 'Authorization' put: 'Bearer QfCCKhxI-HwAAAAAAAAGdeT916yqY4tkX3EN6EW2S3EMxYyv5Xky9LeCxuGi8_o7'; entity: (ZnEntity with: (STONJSON toString: { #path->'demo.txt' } asDictionary) type: ZnMimeType applicationJson); post.
Does that work ?
yes, it does thanks a lot -- View this message in context: http://forum.world.st/Zinc-newbie-question-How-to-get-file-metadata-from-Dro... Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
participants (3)
-
jb -
Johannes Brauer -
Sven Van Caekenberghe