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
- lucasromeiro8 years agoExplorer | Level 3
Cool, I get it.
I liked your idea of generating a link and the user copy it in the browser and enter the code in the program!
But I have some questions about that.
I think you can help me in them:
Earlier you told me that I have 2 options:
- Use My Account Token
- Use OAuth2 and store Tokens on my device.
Right?
How do I use the Token of my application to authenticate? Do I get a get in some specific format and receive some confirmation?
In the second case, I would use OAuth2 to store the tokens, but for that I would need the link for the user to paste into the browser as you suggested in the previous message. right? But, how can I generate a link if I do not have the user's key (client_ID) app?
As for uploading files, my system will always work with small files, it will never exceed 150Mb and I will always transfer one file at a time!
I think I'll use this:
https://www.dropbox.com/developers/documentation/http/documentation#files-upload
But I have not yet arrived in this part, first I need to be able to authenticate before I can upload ...
As I said earlier, I want to make a library for arduino. This will make things easier for other people. I'll also use it for my masters degree.
You have helped me a lot and I want to put your name in thanks, can I post?
Thanks, I think we can do this! :grinning: - lucasromeiro8 years agoExplorer | Level 3
Greg-DB
I made some progress.
I learned that through a request the dropbox already returns the token and other information !!
example:
https://www.dropbox.com/oauth2/authorize?response_type=token&client_id=g0xkpmfuXXXXX&redirect_uri=https://localhost
Returns:
https: // localhost / # access_token = NI7PL_K93wcAAAAAAAAcseCfBxabh2Pb1Zw-5IjC0Vd1lDEKKr1cWyIXXXXXXX & token_type = bearer & uid = 5043908 & account_id = dbid% 3AAAB-FHGsciRVJdVo4D4apeASBLPFXXXXXX
Informing only the client_id.
I read in the documentation that with this information I can already access my dropbox. But in the command line whenever I make a request nothing returns me ....
for example, I tried to make this request for user information:
curl -X POST "https://api.dropboxapi.com/2/users/get_current_account"
--header "Authorization: Bearer NI7PL_K93wcAAAAAAAAcseCfBxabh2Pb1Zw-5IjC0Vd1lDEKKr1cWyIjOXXXXX"
But nothing returns ... I do not understand why ...
I connected to:
server: api.dropboxapi.com
port: 443 - Greg-DB8 years ago
Dropbox Community Moderator
[Cross-linking for reference: https://stackoverflow.com/questions/50185625/upload-file-to-dropbox-by-terminal-command-line#50185625 ]
lucasromeiro I see that you also posted on six other old/unrelated threads about this. We're happy to have you on the forum to engage with us an other developers, but please refrain from spamming duplicate comments like this. I've removed your other comments on those threads, and we'll continue to help you here.
Anyway, I don't see anything obviously wrong with your latest get_current_account code. I recommend adding the --verbose flag to curl so you can get more output.
- chirstius8 years ago
Dropbox Staff
The "token from developer account" method is just using the token you can generate for yourself from the developer console.
Go to: https://www.dropbox.com/developers/apps
Login, if required, select your app. Scroll to the OAuth 2 section and under 'Generated Access Token', click generate:
This will link your app to your account and give you back an API access token, you can use that token to test your curl commands for the API endpoints. This method of authentication is there to make it easier for you to test against your own account quickly.
To enable other users to add your app to their Dropbox, you need to take them through the OAuth flow we discussed, and you tested earlier in this conversation. Where you would have them paste the authorization URL string into a browser and then enter the code generated back into the console.
You use that code to make a call to https://api.dropboxapi.com/oauth2/token which is documented under the 'Authorization' section of the HTTP endpoints documentation found here: https://www.dropbox.com/developers/documentation/http/documentation
A sample curl POST to this endpoint might look like this:
curl -X POST https://api.dropboxapi.com/oauth2/token \ --data "code=<code from user>&grant_type=authorization_code&client_id=<your app key>&client_secret=<your app secret>"This should return a valid API access token you can use to access that users account.
Once you have that token and you want to upload content, refer to:
https://www.dropbox.com/developers/documentation/http/documentation#files-upload
Since you said the files will be small (<150MB) that endpoint should be all you need, there is a curl example right in the documentation that you can edit to fit your needs (focus on the Dropbox-API-Arg header information)All other file operations have similar curl-based examples in the documentation which should point you in the right direction once you have your access tokens sorted out.
I hope this gets you moving towards a working solution.
-Chuck
- lucasromeiro8 years agoExplorer | Level 3
Cool! So I'm on the right track!
I have already done this and I have my token.
I understood now that this was to facilitate.
What I do not understand is that I put my token in the commands and send ... anyway they do not work!
Look:What I do not understand !!
The commands are not working, none worked so far ...
I already tried with my token that I took as you described above and replaced in the command and also I was already in the documentation and I clicked to him to fill alone the token in the command. It gets filled, I send the command, but it also does not work.
I think there is something wrong with the commands, maybe something is missing that is not in the documentation ...
For example, I tried this command that is simple and only returns space, but does not work:curl -X POST https://api.dropboxapi.com/2/users/get_space_usage \ --header "Authorization: Bearer NI7PL_K93wcAAAAAAAAcu3AuVqxJiD6CjL0njHjUsM3EwczSjjeKJIny-lxxxxxxx"
The command that sent me above I could not test, because I did not understand how to fill in the "code = <code from user>". I tried to put the tokens on but they did not work.
I looked at the documentation and the link you sent me to upload ... but I can not send any commands yet to be able to explore other things ...
Any command I send, always returns the same error:I also tried to send the commands through this site. Did not work.
I suspect something is missing from the command or is incomplete in the documentation. Friends also failed to send via socket ...I think I'm missing something simple.
- lucasromeiro8 years agoExplorer | Level 3
Olá!!
Eu enviei os comentarios em topicos que eram relacionados. Percebi que algumas pessoas estavam com alguma semelhanca com minha duvida. Pedi ajuda para elas... Não sabia que isso era errado. Me desculpe.
Pois e, o comando está certo! Eu não entendo porque em lugar nenhum consigo fazer ele funcionar, ja tentei usar varios programas, ja tentei sites etc... Mas não funciona...
Olha a resposta acima, eu explico mais.
Será que estou tentando conectar no endereco errado? algum argunto errado ou faltando??
Sobre o --verbose. como posso inserir?
Todos os codigos que testo retornam o mesmo erro...
Tenta por eles em: https://onlinecurl.com/
Ou tenta enviar via socket...
Sempre recebo algo como:
HTTP/1.1 400 Bad Request
Server: nginx
Date: Tue, 08 May 2018 21:27:40 GMT
Content-Type: text/html
Content-Length: 25658
Connection: close
ETag: "5a7b9900-643a"
X-Dropbox-Request-Id: 71492938f986f1cc2fdcab1000320cc8
<!DOCTYPE html>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Dropbox - 4xx</title>
<link href="https://cfl.dropboxstatic.com/static/css/error.css" rel="stylesheet" type="text/css"/>
<link rel="shortcut icon" href="https://cfl.dropboxstatic.com/static/images/favicon.ico"/> - chirstius8 years ago
Dropbox Staff
If you are sending this over a raw socket then the curl commands won't work directly, they will show you what you need to send, but if you're truly at the level of raw sockets you need to implement the HTTP protocol yourself directly. Sending the literal curl command text down the socket to the Dropbox API server will not work. Explaining how to implement HTTP over a socket is outside the scope of support we can provide on this forum so I will not be able to help you there.
Perhaps you can find a simple/lightweight HTTP library for arduino that you can install, or that is present by default, to make this easier. But if not, I do know there are several samples available by searching for "arduino http post"
-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!