Andrei Herford
Andrei Herford

Reputation: 18745

DropNet WP 8 integration - Unable to connect

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) => {
                ...
        });
    }
}

Upvotes: 0

Views: 574

Answers (2)

vijayst
vijayst

Reputation: 21856

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.

Upvotes: 1

dkarzon
dkarzon

Reputation: 8038

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.

Upvotes: 2

Related Questions