Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by altropetrolio · Dec 14, 2020 at 05:13 AM · apiwebrequesthttpsdropbox

DropBox Https Api Request : What should I do?

Hello everyone. I'm going crazy with DropBox Api Http Never used an Api Call and don't know how to manage it.

What should I Do : 1. Get access to my Public Folder 2. Find Sharable Link for images

My Question How should be the script to "send the request"? (can't figure out ...) (need a full script) How should be the "response" and how I should deserialize it (JsonUtily?)

Thank you a lot.

For now I only figured out that I should use WebRequest (but I don't know how). Already configured DropBox App and I have the Token. From here and on I cannot understand what I should do...

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by xxmariofer · Dec 14, 2020 at 09:27 AM

I dont know how dropbox works, if they only upload changes to files or they upload the full file everytime (i imagine the first one) but you need a php script on your server (app?) to handle the upload of files, here is a small example of a zip upload (I have edited it because it is code from an old project with extra stuff you dont need so maybe I deleted something but is pretty much this)

         WWWForm formData = new WWWForm ();
 
         byte[] formBytes;
 
         formData.AddField("action", "zipupload");
 
         if (File.Exists("path/to/the/files/example.zip")) //HERE YOU FIND THE FILE TO UPLOAD
         {
             formBytes = File.ReadAllBytes("path/to/the/files/example.zip");
             formData.AddBinaryData("form", formBytes, "Form.zip");
         }
 
         string url = "http://URLtoYourSite/upload.php"; //CHANGE TO YOUR URL
 
         using (UnityWebRequest www = UnityWebRequest.Post (url, formData)) {
 
             string authorization = Authenticate (stUsername, stPassword); //only use this if you need user password
             byte[] boundary = UnityWebRequest.GenerateBoundary ();
 
             www.SetRequestHeader ("Authorization", authorization);
 
             yield return www.SendWebRequest ();
 
             if (www.isNetworkError || www.isHttpError) {
                 Debug.LogError (www.error);
             } else {
                 Debug.Log ("Files uploaded.");
                 StringBuilder sb = new StringBuilder ();
                 foreach (KeyValuePair<string, string> dict in www.GetResponseHeaders ()) {
                     sb.Append (dict.Key).Append (": \t[").Append (dict.Value).Append ("]\n");
                 }
 
                 Debug.Log ("Response headers: " + sb.ToString ());
                 Debug.Log ("Response text: " + www.downloadHandler.text);
             }
         }

`then you need the php to move the files to your location in your server

Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image altropetrolio · Dec 14, 2020 at 07:05 PM 0
Share

Hi, first of all thank you for your contribute. As far as I understood I should only send some call, not php.

This is what DropBox Report Request and response formats In general, the Dropbox API uses HTTP POST requests with JSON arguments and JSON responses. Request authentication is via OAuth 2.0 using the Authorization request header or authorization URL parameter. The .tag field in an object identifies the subtype of a struct or selected member of a union. When specifying a Void member of a union, you may supply just the member string in place of the entire tagged union object. For example, when supplying a Write$$anonymous$$ode, you can supply just "mode": "add" instead of "mode": {".tag": "add"}}. This shorthand is not allowed for non-Void members. For example, the following is not allowed for a Write$$anonymous$$ode, as update is not a Void member: "mode": "update".

avatar image xxmariofer altropetrolio · Dec 15, 2020 at 08:51 AM 0
Share

Oh! i though you were trying to build your own Dropbox app. Without knowing at all how the dropbox api works here is a sample code that does what you asked, you just need to use JsonUtility to parse the send and inco$$anonymous$$g data (you need to create a class as a base for the parse)

         WWWForm form = new WWWForm();
         form.AddField("json", data);
 
         using (UnityWebRequest www = UnityWebRequest.Post("http://URL", form))
         {
             yield return www.SendWebRequest();
 
             if (www.isNetworkError || www.isHttpError)
             {
                 Debug.Log(www.error);
             }
             else
             {
                 string message = www.downloadHandler.text;
                 Debug.Log("response: " + message);
             }
         }
avatar image altropetrolio xxmariofer · Dec 19, 2020 at 04:35 PM 0
Share

Thank you a lot! For now I have no idea what it does... but I will try to figure out how to use it. ( I'm just a begginer...some advanced form of code I'm unable to unterstand clearly...)

As far I can understand http://URL should pass the "access" to DropBox Api...than I "recall" it again with others Api codes.

Ok... it should work. Thank you a lot for your time. Really appreciated.

Show more comments
Show more comments
avatar image
0

Answer by altropetrolio · Dec 22, 2020 at 06:04 AM

AFTER ABOUT 20HR OF STUDY I've managed to have a working Script...Really I fell like I was under torture :-). This script maybe is not "Super Clean" (I've a lot of missing info about true coding). It took the "API URL", pass BODY PARAMETERS, pass Authorization Token. I was unable to use the WebRequest.Post because of Json Decode Warning. In the way below insted it work! Thank you for Help @xxmariofer. (Now I'm stucked in JsonDeSerialize but maybe i will use some dirty String Search, only need to find Shared_Link in Response)

 public string Url = "https://api.dropboxapi.com/2/sharing/create_shared_link_with_settings";
         public string Token = "MySuperSecretToken";
         public string Path = "/Shared Folder";
 
 // STRUCT DEI PARAMETRI DEL BODY
         public struct MyStruct
         {
             public string path;            
         }    
         // GENERO STRUCT
         public MyStruct DataFormBody;
 
 IEnumerator Post_Easy()
             {
                 // Assegno la Path
                 DataFormBody.path = Path;
                 // Converto in JSon
                 string JSonBody = JsonUtility.ToJson(DataFormBody);
                 // Passo il Parametro POST a UnityWebRequest
                 var request = new UnityWebRequest(Url, "POST");
                 // Codifico il Json in Byte Utf8
                 byte[] bodyRaw = System.Text.Encoding.UTF8.GetBytes(JSonBody);
                 // Assegno il Body in Parametro Upload
                 request.uploadHandler = (UploadHandler) new UploadHandlerRaw(bodyRaw);
                 // Assegno il Download del Response
                 request.downloadHandler = (DownloadHandler) new DownloadHandlerBuffer();
                 // Imposto l'Header di Autorizzazione
                 request.SetRequestHeader ("Authorization", "Bearer " + Token);
                 // Imposto la tipologia di comunicazione
                 request.SetRequestHeader ("Content-Type", "application/json");
                 // Invio la richiesta alla API DropBox
                 yield return request.Send();
                 
                 // Verifica se ci sono errori di connesione
                  if (request.isNetworkError || request.isHttpError)
                  {
                      // Riporta l'errore di connesione
                      Debug.Log(request.error);
                      // Riporta ulteriori informazioni riguardo l'errore
                      string message = request.downloadHandler.text;
                      Debug.Log("response: " + message);                     
                  }
                  else
                  {
                     // Scarica la risposta
                     string message = request.downloadHandler.text;
                     // Debug Status Code
                     Debug.Log("Status Code: " + request.responseCode);
                     // Debug Risposta
                     Debug.Log("response: " + message);
                     // Scrivo la risposta in un file
                     File.WriteAllText("DropBox Response.txt",message);                    
                  }                
             }
 
 




Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Utsav_paracosma · Mar 22 at 05:26 AM 0
Share

Hello, I am working on a similar project and am having a problem with getting the token. Could you tell me how you generated the secret token for the code .

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

141 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can't Send a form to a server(POST) due to CORS error in a WEBGL build 1 Answer

unitywebrequest doesnt work with https 0 Answers

crossdomain.xml not working with ssl and facebook canvas 1 Answer

HttpWebRequest.GetRequestStream() https certificate error exception 6 Answers

How to avoid reestablishing an HTTPS request, use Connection: Keep-Alive or reuse WWW object? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges