0

I have been trying to connect my Windows Phone 8 app to Dropbox using DropNet. Unfortunately with little success.

According to the examples and the documentation on the DropNet Git Page I tried two different ways to connect the app the Dropbox:

The first was is "classic" solution presented directly on the DropNet Git Page. After getting the RequestToken a internal WebBrowser control is used to navigate to the Dropbox Login Page. However I was not able to get this working. Generating the token and and the request URL is no problem. But the page is not loaded correctly in the WebBrowser control. The control just flickers but does not show any content. The control is working correctly when I navigate to any other page (like google or so).

The second solution works pretty much the same. Instead using a WebBrowser control the URL is called directly and thus the build in Browser App is used. This workes without a problem. After the Login is complete the user is redirected to the app using a custom URL Scheme. However I do not know how to proceed after getting back to the app. The request result already contains an access token. Is it still necessary to use GetAccessTokenAsync()? This thows an error saying "Parameter not found: oauth_token"?

How to proceed to use Dropbox?

// Step 0. Create the Client
_client = new DropNetClient("API KEY", "API SECRET");

// Step 1. Get Request Token
_client.GetTokenAsync(
    (userLogin) => {
        // Step 2. Authorize App with Dropbox

        // Version 1 - Using a WebBrowser Control
        string url = _client.BuildAuthorizeUrl(AuthRedictURI);
        loginBrowser.LoadCompleted += new System.Windows.Navigation.LoadCompletedEventHandler(loginBrowser_LoadCompleted);
        loginBrowser.Navigate(new Uri(url));

        // OR

        // Version 2 - Calling the URI directly --> Redirect to Browser App --> Use Custom URL Scheme to return to app
        string url = _client.BuildAuthorizeUrl(DropNet.Authenticators.OAuth2AuthorizationFlow.Token, AuthRedictURI);
        WebBrowserTask webbbrowser = new WebBrowserTask();
        webbbrowser.Uri = new Uri(url);
        webbbrowser.Show();
    },
    (error) => {
        //Handle error
    }
);


// Continue Connection Version 1
private void loginBrowser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e) {
    //Check for the callback path here (or just check it against "/1/oauth/authorize")
    if (e.Uri.AbsolutePath == AuthRedictURI) {
        //The User has logged in!
        //Now to convert the Request Token into an Access Token
        _client.GetAccessTokenAsync(
            (response) => {
                ...
            },
            (error) => {
                ...
        });
    } else {
        //Probably the login page loading, ignore
    }
}


// Continue Connection Version 2
// --> Returned to App using custom URL Scheme. The result is contained in
//     the Query string that is parsed into a IDictionary
public void ContinueConnect(IDictionary<string, string> redirectQueryResult) {
    // Possible Response after successful login
    //key: access_token, value: 5915K1yPZ6kAAAAAAAAAAeaA9hsRN4PCF-PVmbgKgZTTfDp3quXeu8zBoTUadu6H
    //key: token_type, value: bearer
    //key: uid, value: 10651049

    if (*Error_Detected = false*) {
        // How to continue here? 
        _client.GetAccessTokenAsync(
            (response) => {
                ...
            },
            (error) => {
                ...
        });
    }
}

2 Answers 2

2

I think you are missing the IsScriptEnabled property on your Browser control. Set this to true to enable Javascript. http://msdn.microsoft.com/en-us/library/windowsphone/develop/microsoft.phone.controls.webbrowser.isscriptenabled(v=vs.105).aspx

I have come across this issue a few times before and it's very annoying.

6
  • Thank you very much for that hint! It works. The page is loaded and displayed correctly. However the Dropbox login is still not working. Now I get to _client.GetAccessTokenAsync(...) but after this is called nothing happens. response and error are not called. No exception. Nothing... Compared to this Version 2 seems to be much cleaner. Problem here is that I do not know how to proceede. Any advise on this? Oct 15, 2013 at 14:35
  • hmm, not too sure. Maybe try attaching to Fiddler (assuming you can run it in the emulator?) and see what the response for that call is?
    – dkarzon
    Oct 15, 2013 at 20:37
  • Which version of DropNet are you using? v1.9.x from NuGet or DropNetRT? DropNetRT might do this a bit nicer with async/await as the original version is based on RestSharp which doesn't seem to like the API too much. But DropNetRT is based on HttpClient which is a lot simpler.
    – dkarzon
    Oct 15, 2013 at 20:39
  • Thanks again for your prompt feedback. I have installed DropNet using NuGet. NuGet shows Version 1.9.6. The DropNet.WindowsPhone assembly that is added to the project has version 1.8.2.0. I re-installed DropNet using NuGet but the problem (no feedback on GetAccessTokenAsync()) is still the same. I installed DropNetRT using NuGet and ran into another problem: GetAccessToken() return a userLogin with Secrete and Token null. The result on Device and emulator is the same. I am sorry for all the touble, but no matter which way I choose they all end up in a dead end... Oct 16, 2013 at 8:42
  • Can you email me your code so I can take a look? Did you attach fiddler to make sure the response was coming back from the server?
    – dkarzon
    Oct 16, 2013 at 20:15
1

I recommend using the https://www.nuget.org/packages/DropboxOAuth2Client/ (DropBoxOAuth2Client) and https://www.nuget.org/packages/oauth2authorizer/ (oAuth2Authorizer) NuGet packages. oAuth2Authorizer is useful to get the access token. And once you get the access token, you can use DropBoxClient which is a simple wrapper for the REST API for any .NET clients.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.