Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
dropbox api HTTP example
#1
From this page: https://www.dropbox.com/developers/documentation
I Got to this page (HTTP): https://www.dropbox.com/developers/docu ... p/overview
I wanted to know if QM could use the HTTP API from the above HTTP page overview.
Specifically about the 'get_account' request.

If it is possible could you give an example of the correct syntax.
I have added the screenshots to the generated code and documentation below (my apologies for the scrolling)
DROPBOX GENERATED EXAMPLE = The page where you can generate a HTTP request based on an token that comes from your account
DROPBOX 'get_account' DOCUMENTATION = documentation about the 'get_account' request.

I assume the 'Http' function should be used?
The goal is to output the RETURNED data in QM (see below in DROPBOX 'get_account' DOCUMENTATION, 'name' , 'surname' etc...)

Macro http_dropbox_api_example
Code:
Copy      Help
Http h
h.Post


DROPBOX GENERATED EXAMPLE:
https://dropbox.github.io/dropbox-api-v ... et_account

Code:
Copy      Help
POST /2/users/get_account
Host: https://api.dropboxapi.com
User-Agent: api-explorer-client
Authorization: Bearer jkllaadddd67y
Content-Type: application/json

{
    "account_id": "12341234"
}
[Image: dropbox_api_1.jpg]

DROPBOX 'get_account' DOCUMENTATION:
https://www.dropbox.com/developers/docu ... et_account
[Image: dropbox_api_2.jpg]
#2
Macro Dropbox get_account
Code:
Copy      Help
out

str accessToken="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ;;you can generate it in your Dropbox app settings page
str accountId="yyyyyyyyyyyyyyyyyyyyyyyy" ;;see next post

typelib WinHttp {662901FC-6951-4854-9EB2-D9A2570F2B2E} 5.1
WinHttp.WinHttpRequest r._create
r.Open("POST" "https://api.dropboxapi.com/2/users/get_account")
r.SetRequestHeader("Authorization" F"Bearer {accessToken}")
r.SetRequestHeader("Content-Type" "application/json")
str body=
F
;{{
;;;;;"account_id": "dbid:{accountId}"
;}
r.Send(body)
ARRAY(byte) a=r.ResponseBody
str s.fromn(&a[0] a.len)

out s
#3
Thank you!

I got the example working, but it seems I gave the wrong request, the request should have been: 'get_current_account'

EXAMPLE CODE FROM DROPBOX

Code:
Copy      Help
POST /2/users/get_current_account
Host: https://api.dropboxapi.com
User-Agent: api-explorer-client
Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxx
Content-Type: application/json

null

The body needs to be "NULL" I assume?
When I modify the example code I get the error.
Code:
Copy      Help
Error in call to API function "users/get_current_account": request body: expected null, got value

I read here how to change the body to NULL but none of the methods work:
http://stackoverflow.com/questions/2112 ... ll-in-json


RETURNS (from dropbox API)
Code:
Copy      Help
{
    "account_id": "dbid:AAH4f99T0taONIb-OurWxbNQ6ywGRopQngc",
    "name": {
        "given_name": "Franz",
        "surname": "Ferdinand",
        "familiar_name": "Franz",
        "display_name": "Franz Ferdinand (Personal)"
    },
    "email": "franz@gmail.com",
    "locale": "en",
    "referral_link": "https://db.tt/ZITNuhtI",
    "is_paired": false,
    "account_type": {
        ".tag": "basic"
    },
    "country": "US"
}

What is the correct the syntax?
#4
To get account id:
Macro Dropbox get account id
Code:
Copy      Help
out

str accessToken="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ;;you can generate it in your Dropbox app settings page

typelib WinHttp {662901FC-6951-4854-9EB2-D9A2570F2B2E} 5.1
WinHttp.WinHttpRequest r._create
r.Open("POST" "https://api.dropboxapi.com/2/users/get_current_account")
r.SetRequestHeader("Authorization" F"Bearer {accessToken}")
r.Send()
ARRAY(byte) a=r.ResponseBody
str s.fromn(&a[0] a.len)

out s
#5
WOW that was fast!!!!

THANK YOU IT WORKS!!!!!!
#6
When you don't know Dropbox access token.

Function DropboxAuthorize

Deleted. Please use Dropbox.qml attached to my next post.
#7
I do not often use smileys, but in this case: Confusedhock: WOW!
!!!!Thank you!!!!
#8
FUNCTIONS:
Dropbox.Authorize
Dropbox.Upload
Dropbox.Download
Dropbox.ListFolder
Dropbox.ListFolderContinue
Dropbox.Delete

I'll create more functions later, if somebody will need it.

See also function JsonToXml:
JSON parser
.


Attached Files
.qml   Dropbox.qml (Size: 14 KB / Downloads: 444)
#9
THANK YOU FOR THIS!!!
This saves me a lot of time!!!!
#10
Sorry to ask this, but:

1)
Could you add: List folder: https://www.dropbox.com/developers/docu ... ist_folder
I tried but I am constantly getting JSON errors.

r.Open => https://api.dropboxapi.com/2/files/list_folder

Code:
Copy      Help
curl -X POST https://api.dropboxapi.com/2/files/list_folder \
    --header "Authorization: Bearer %%%%TOKEN%%%%" \
    --header "Content-Type: application/json" \
    --data "{\"path\": \"/Homework/math\",\"recursive\": false,\"include_media_info\": false,\"include_deleted\": false,\"include_has_explicit_shared_members\": false}"

Code:
Copy      Help
"path": "/Homework/math",
    "recursive": false,
    "include_media_info": false,
    "include_deleted": false,
    "include_has_explicit_shared_members": false
}

=================================================================

2)
And how can I make the beneath code for downloading work properly.
It works, but the contents of the file is put in "rt" at the bottom of below code.
I want to acutually save the fale to local disk. (Do I need to use the __stream class?)

Macro dropbox_download
Code:
Copy      Help
str to_download="/Homework/math/test3.csv"

;;________________________________________________________
;;|
;;| Authorizes your Dropbox application (actually the caller macro) to use Dropbox API with user's Dropbox account.
;;|
;;| appKey - from https://www.dropbox.com/developers/apps -> your app -> App key.
;;| appSecret - from https://www.dropbox.com/developers/apps -> your app -> App secret.
;;|
;;[PKEK8]_________________________________________________


str _token=""
str appKey=""
str appSecret=""


;authToken -> bearer token
WinHttp.WinHttpRequest r._create
r.Open("POST" F"https://api.dropboxapi.com/1/oauth2/token?code={_token}&grant_type=authorization_code&client_id={appKey}&client_secret={appSecret}")
r.Send()


;;________________________________________________________
;;|
;;| Start the DOWNLOAD
;;|
;;[XJPS4]_________________________________________________

r.Open("POST" "https://content.dropboxapi.com/2/files/download")
r.SetRequestHeader("Authorization" F"Bearer {_token}")

str arg=
F
;{{
;"path": "{to_download}"
;}
arg.findreplace("[]" " ")
r.SetRequestHeader("Dropbox-API-Arg" arg)
r.Send()

str rt=r.ResponseText
if(r.Status!=200) end _s.from(r.StatusText ".  " rt)

out rt ;; OUTPUTS CONTENTS OF FILE!

If needed (it is almost same as upload):

r.Open => https://content.dropboxapi.com/2/files/download

Code:
Copy      Help
curl -X POST https://content.dropboxapi.com/2/files/download \
    --header "Authorization: Bearer %%%%TOKEN%%%%" \
    --header "Dropbox-API-Arg: {\"path\": \"/Homework/math/Prime_Numbers.txt\"}"

Code:
Copy      Help
{
    "path": "/Homework/math/Prime_Numbers.txt"
}
#11
Updated.
dropbox api HTTP example
#12
Thank you!!!


Forum Jump:


Users browsing this thread: 1 Guest(s)