Nisarg
Nisarg

Reputation: 21

Windows Phone with DropNet

I am writing a Windows App on Windows Phone Emulator to communicate with DropBox account and am using DropNet package from NuGet gallery.

The page that I am referring is: http://dkdevelopment.net/what-im-doing/dropnet/

Here are the steps I have done:

Step 1) Creating the client

DropNetClient GlobalClient = new DropNetClient("TOKEN", "SECRET", "testUserName", "testPassword");

I am not sure what goes in userToken and userSecret, it can't be hard-coded username and password!

Step 2) Requesting Token

GlobalClient.GetTokenAsync((userToken) =>
        {
            //Dont really need to do anything with userLogin,
            //DropNet takes care of it for now
        },
        (error) =>
        {
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                MessageBox.Show(error.Message);
            });
        });

Step 3) Building authorizing URL

var url = GlobalClient.BuildAuthorizeUrl("http://dkdevelopment.net/BoxShotLogin.htm");

Step 4) Redirecting browser to DropBox Login Page. After this, DropBox does allow to login, but it displays this warning: "The request to link the app is invalid" And more importantly, the browser does not get redirected to http://dkdevelopment.net/BoxShotLogin.htm. This indicates something went wrong. Not sure what though.

Uri testUri = new Uri(url.ToString());
        WebBrowserTask task = new WebBrowserTask();
        task.Uri = testUri;
        task.Show();

Step 5) This does not work. GlobalClient.UserLogin.Token and GlobalClient.UserLogin.Secret does not get set.

GlobalClient.GetAccessTokenAsync((accessToken) =>
        {
            //Store this token for "remember me" function
            GlobalClient.UserLogin.Token = accessToken.Token;
            GlobalClient.UserLogin.Secret = accessToken.Secret;
        },
        (error) =>
        {
            Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    MessageBox.Show(error.Message);
                });
        });

Anybody knows how to fix this?

Thanks!

Upvotes: 0

Views: 472

Answers (2)

Jason
Jason

Reputation: 860

The issue is in the following code:

UserLogin.Token = userToken.Token; 

Assigning a value to token doesn't mean the underlying credentials are set for the request. This is only done when you call the following:

UserLogin = userToken;

Poor design in the class interface if you ask me. There should be no difference between calling UserLogin.Token = Something, and UserLogin = NewLogin (with regards to underlying business rules).

Upvotes: 0

Nisarg
Nisarg

Reputation: 21

I figured out the problem. In Step 2, request token needs to be stored in order to build correct authorize URL and that request token needs to be passed as the first parameter. However when I try to store in the statement lambda like this, it does not get stored. What's the issue here? I think it's the way I might be using lambdas.

GlobalClient.GetTokenAsync((userToken) => 
{ 
    infoTextBlock.Text = userToken.Token; 
    GlobalClient.UserLogin.Token = userToken.Token; 
}
(error) => 
{ 
});

Thanks!

Upvotes: 0

Related Questions