Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
lucasromeiro
8 years agoExplorer | Level 3
Access and file upload using command line (RAW socket)
Hello everyone.
I am trying to login and upar a file in the dropbox using command line, (RAW socket).
I am having difficulty understanding how to do it, because I always get error from my commands.
I am using the reference:
https://www.dropbox.com/developers/documentation/http/documentation
What do I do:
I connect to the dropbox at the following address:
Server IP: api.dropboxapi.com
PORT: 443
I send the commands that have in the above address, to log or send file, but only returns me error, for example:
Sending:
curl -X POST https://api.dropboxapi.com/2/auth/token/from_oauth1 \
--header "Authorization: Basic ZzB4a3BtZnUwMjVwbjhmOmtuYWdoMzl3YTc1cxxxxxxxxt" \ "
--header "Content-Type: application / json" \
-data "{\" oauth1_token \ ": \" g0xkpmfu025xxxx \ ", \" oauth1_token_secret \ ": \" knagh39wa75xxxx \ "}"
I get:
HTTP / 1.1 400 Bad Request
Server: nginx
Date: Thu, 03 May 2018 15:54:37 GMT
Content-Type: text / html
Content-Length:
Connection: close
ETag: "5a7b9900-643a"
X-Dropbox-Request-Id: bd49b7d1aafce148d39e89d17e580d7f
<! DOCTYPE html>
Any command I send, I always get it! I do not understand what I'm doing wrong ....
Can someone help me?
Is there an example command for me to send to test the connection?
17 Replies
Replies have been turned off for this discussion
- Greg-DB8 years ago
Dropbox Community Moderator
From the sample you provided, I see that you're trying to call /2/auth/token/from_oauth1. This endpoint is only meant for use if you already have pre-existing OAuth 1 access tokens (e.g., retrieved in the past for API v1), which you would plug in there. If you are only starting development now, you would not have OAuth 1 access tokens and so should not be using this endpoint.
If you don't have pre-existing OAuth 1 access tokens, you should send the user through the normal OAuth 2 app authorization flow. You can find information on how that works in the OAuth guide here:
https://www.dropbox.com/developers/reference/oauth-guide
The documentation for the OAuth 2 app authorization flow can be found here:
https://www.dropbox.com/developers/documentation/http/documentation#authorization - lucasromeiro8 years agoExplorer | Level 3
Cool! I understand that I need to use OAuth2, correct?
I looked at this link that you sent me, but I did not understand how I send the authorization command, I did not find an example.
https://www.dropbox.com/developers/documentation/http/documentation#authorization
can you help me? - chirstius8 years ago
Dropbox Staff
hello lucasromeiro,
As mentioned in the link you referenced, to begin the OAuth 2 flow you would just make a simple GET request, that should be made via the system browser, to:
https://www.dropbox.com/oauth2/authorize
And supply the parameters as listed, at a bare minimum your request URL would look like:
https://www.dropbox.com/oauth2/authorize?response_type=code&client_id=abcdefg123
response_type can either be 'code' or 'token' and client_id is your app key from the developer console (as listed in the description of the /oauth2/authorize documentation).
In this case, if you use the code flow, the user will be presented with a page asking them to login, if they are not already, and then to authorize your application. If they allow it they will be presented a code they can enter back into your app.
Your app can then use:
https://api.dropboxapi.com/oauth2/token
to convert that code into an actual API token you can use to make calls against the Dropbox API. Pay attention to the authorization requirements of this endpoint (again documentation is covered in the link you referenced). This is a POST request vs. a GET for the previous step so adjust and encode parameters accordingly.
Hope that helps get you past this,
-Chuck
- lucasromeiro8 years agoExplorer | Level 3
Hello chirstius
Thanks for helping me!
I think you understood what I need.
I'm still saying.
I'm going through parts ...
First I tried to make the GET using the pattern I passed above.
But it still does not work ...
When I use the terminal / command line to send the GET, I have no response ...
Look below the commands I sent:
Server: www.dropbox.com
Door: 443 or 801:
GET /oauth2/authorize?response_type=code&client_id=g0xkpmfu025XXXX/ HTTP/1.1
Host: dropbox.com2:
GET /oauth2/authorize?response_type=code&client_id=g0xkpmfu025XXXX/ HTTP/1.1
Host: dropbox.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.30729)
Accept: application/octet-stream
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Test these 2 formats, in both I got no other server response, neither error, nor success ...
What could it be?
I did not succeed in anything, because I could not do it ...
Thank you very much for your help !! - chirstius8 years ago
Dropbox Staff
That GET request needs to be made from a browser. You can script launching the system browser on your device and pointing it to the generated URL which will make a simple GET request by default. I should have been more clear on that in my previous response.
Have you tried just pasting your URL into a browser to see if it's working at all? I'd start there to make sure it's well-formed and that Dropbox responds with a proper authentication window. Then you can look at how to script launching the browser to open that URL.
-Chuck
- lucasromeiro8 years agoExplorer | Level 3
Hello! It worked!
I pasted the URL into the browser and it returned an authentication window!
Thank you for explaining better.
But in my case, I need to do everything by terminal / command line.
Because my solution will be all in command line (raw socket). how can I do this command line authentication?
it's possible?
Every time I use the system, will I need to do this or is it only once?
Thanks a lot for the help!
- chirstius8 years ago
Dropbox Staff
Once you have the token it's good until it is revoked. If you are only planning on doing this for a single user/account (you) you can probably use a generated token from your developer console (which is just a shortcut to link the app to your Dropbox directly) and avoid the OAuth 2 flow entirely. If you need this to run against multiple accounts you'll want to find a workable solution for the OAuth 2 flow and make sure you have a secure mechanism in place for storing API tokens.
-Chuck
- lucasromeiro8 years agoExplorer | Level 3
Nice, i got it.
So I have 2 options:
- Use Token from my developer account
- Use OAuth2 and store Tokens on my device.
I want to learn how to do both ways.
Because I'll need the 2.
I have a secure location to store the tokens to use OAuth 2.
But I do not know how to authenticate the uduário through OAuth 2 through raw socket.
I need to know what to send to authenticate the user using the 2 options (Token and OAuth 2)
Can you help me? I do not know what commands I have to send for this, I believe a GET or POST. But I do not know the structure.
I need help. - lucasromeiro8 years agoExplorer | Level 3chirstius
if I can do everything from the command line / terminal, I can put it in my project! I want to make a repository for arduino that makes sending and manipulating files in the dropbox. So I need examples and understand how to log in and upload a file. so I adapt the upload command to the other manipulation functions ... that is why the user can not access the browser. I am learning from your help. Now I only need to learn how to log in the 2 ways and upload a file. as I said above. can you help me? Sorry to bother you guys. I want to make this library to help other people who want to use Dropbox in their projects but have no Arduino API. - chirstius8 years ago
Dropbox Staff
I'm not sure there's an easy way around authenticating through the browser, that's really how the OAuth2 workflow needs to run for us. What you might be able to do is generate the authorization link, write it to the console/terminal and ask your user to copy it into a browser on another device. Then prompt for the code that comes back. They can enter the code into the terminal, and you can complete authorization from there and store their token. Since this is a one-time action it might be an acceptable workaround.
As to your other question(s) around uploading, there is the singular /upload endpoint for files of 150MB or smaller:
https://www.dropbox.com/developers/documentation/http/documentation#files-uploadAnd there are chunked session endpoints for files larger than 150MB:
https://www.dropbox.com/developers/documentation/http/documentation#files-upload_session-starthttps://www.dropbox.com/developers/documentation/http/documentation#files-upload_session-append_v2
https://www.dropbox.com/developers/documentation/http/documentation#files-upload_session-finish
If you are committing a large number of concurrent uploads.
The singular upload endpoint example in the documentation is self-contained. If you are using curl it should work as-is to upload smaller files.
For chunked uploads, you would need to determine what mechanism is available to you to chunk the files and provide that data to the endpoints (/start and /append_v2). That mechanism is a bit outside the scope of Dropbox API support though and is highly dependant on the platform and libraries available to you which I can't help with.
I do hope this gets you a bit closer to a solution,
-Chuck
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!