Anyone tried to integrate dropbox in unity?

Hi. I got a complete implementation of dropbox login/upload/download through their REST API and Unitys build in WebRequest function.

The only thing not working is the authentication and Dropbox are not exactly getting back to me.
The problem is:

  • User authenticates app through OAuth 2 and I get a correct key back.
  • Now I want to trade the key for an access token and I get an error 500 (server error).

So while I wait for dropbox support (been waiting 3 weeks now), did anyone make this work in unity?
(They did answer that they can’t see what’s wrong)

Thanks in advance

Odin

@TwistedSage Wondering if you found a method for doing this? Looking myself.

Anyone got this to work? @TwistedSage , would it be possible to get a sample on the login through REST you did in Unity?

@TwistedSage - don’t if you’re still looking for an answer, but given that a few people have been asking if you got this to work I thought I’d place a a possible solution here.

Given that you’re encountering an error 500 when trying to exchange the OAuth 2 key for an access token, it’s possible that the issue may be with how you’re making the request to Dropbox’s API. A 500 error typically indicates that something went wrong on the server side, but this could also be due to the server not understanding the request.

You could exchange the OAuth 2 authorization code for an access token in Unity using the UnityWebRequest class (warning untested):

string authorizationCode = "<Your Authorization Code>";
string clientId = "<Your Client ID>";
string clientSecret = "<Your Client Secret>";
string redirectUri = "<Your Redirect URI>";

Dictionary<string, string> headers = new Dictionary<string, string>();
headers.Add("Content-Type", "application/x-www-form-urlencoded");
headers.Add("Authorization", "Basic " + System.Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(clientId + ":" + clientSecret)));

WWWForm form = new WWWForm();
form.AddField("code", authorizationCode);
form.AddField("grant_type", "authorization_code");
form.AddField("redirect_uri", redirectUri);

UnityWebRequest www = UnityWebRequest.Post("https://api.dropbox.com/1/oauth2/token", form.data, headers);
yield return www.SendWebRequest();

if (www.isNetworkError || www.isHttpError)
{
    Debug.Log(www.error);
}
else
{
    Debug.Log("Access Token: " + www.downloadHandler.text);
}

This script is attempting to POST the request to Dropbox’s token endpoint with the appropriate headers and body parameters.

If the issue persists, post the error response body here to provide some additional information that might help pinpoint the problem. It could be that the OAuth 2 key is not valid or that the request body is not formatted correctly.