3

So I'm new to using external API's for projects, but I had an idea and I'd like to see if I can properly get files uploaded to dropbox. I've gone through the steps to get the key and token, and I've begun testing but I have run into an error:

An unhandled exception of type 'System.ArgumentNullException' occurred in DropNet.dll Additional information: Value cannot be null.

Update: Looking into the error further the actual parameter that is null would be "userLogin"**

This is my code before the error: //using Dropnet;

DropNetClient _client = new DropNetClient("API_KEY", "API_SECRET", DropNetClient.AuthenticationMethod.OAuth1);

The code that produces the error:

var url = _client.BuildAuthorizeUrl();

And my code following the error:

Process.Start(url);
_client.GetAccessTokenAsync((accessToken) =>
    {
        _client = new DropNetClient("API_KEY", "API_SECRET", accessToken.Token, accessToken.Secret);
    },
    (error) =>
    {
        MessageBox.Show(error.Message);
    });
try
{
    _client.UploadFile("/", "test.txt", ReadFile(@"D:\Classes\Documents\test.txt"));

    MessageBox.Show("Successfully uploaded to Dropbox.", "Uploaded to Dropbox");
}
catch (Exception dropboxEx)
{
    MessageBox.Show("Error: " + dropboxEx.Message);
}

I am fairly sure the error has something to do with the deceleration of the client, perhaps I'm misusing the key and secret? Or my OAuth uri could possibly be incorrect, I'm not really sure but in case it matters here is what my dropbox developer page looks like:

My Dropbox Page If you need any more information please let me know, thanks for any help!

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Matt
  • 621
  • 1
  • 6
  • 24

1 Answers1

1

Fixed: needed to add a simple snipped of code underneath my deceleration of _client

UserLogin login = _client.GetToken();
_client.UserLogin = login;
abatishchev
  • 98,240
  • 88
  • 296
  • 433
Matt
  • 621
  • 1
  • 6
  • 24
  • That seems like a pretty important property given the nature of the library, they could perhaps use some more error handling around the use of it and return a meaningful exception. – CodeCaster Jan 27 '14 at 20:42
  • @CodeCaster Yes I agree entirely, I was able to figure it out by using a try {} catch (ArgmentNullException){} which then displayed which parameter was actually null. I have found a lot of stuff with third party API's is less clear and well constructed especially when it comes to errors (and handling them) – Matt Jan 27 '14 at 20:46
  • 1
    The GetToken() function actually sets that property itself the problem was you weren't calling that in the first place. You can also use the GetTokenAndBuildUrl() function to get the token and return you the login url in the same function. https://github.com/dkarzon/DropNet/blob/master/DropNet/Client/User.Sync.cs#L31 – dkarzon Jan 28 '14 at 18:15
  • Just a note, you don't need to recreate the _client object after you get the access token. This function will automatically set the UserToken property again on the client, it is returned to allow you to save it to remember the user. – dkarzon Jan 28 '14 at 18:19