0

我一直在尝试使用 DropNet 将我的 Windows Phone 8 应用程序连接到 Dropbox。不幸的是,收效甚微。

根据 DropNet Git 页面上的示例和文档,我尝试了两种不同的方式将应用程序连接到 Dropbox:

第一个是直接在 DropNet Git 页面上呈现的“经典”解决方案。获得 RequestToken 后,使用内部 WebBrowser 控件导航到 Dropbox 登录页面。但是我无法让这个工作。生成令牌和请求 URL 没有问题。但是该页面未在 WebBrowser 控件中正确加载。控件只是闪烁,但不显示任何内容。当我导航到任何其他页面(如谷歌左右)时,该控件正常工作。

第二种解决方案的工作原理几乎相同。而是使用 WebBrowser 控件直接调用 URL,因此使用浏览器应用程序中的构建。这没有问题。登录完成后,用户将使用自定义 URL 方案重定向到应用程序。但是,我不知道在返回应用程序后如何继续。请求结果已包含访问令牌。是否仍然需要使用 GetAccessTokenAsync()?这会出现错误提示“找不到参数:oauth_token”?

如何继续使用 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) => {
                ...
        });
    }
}
4

2 回答 2

2

我认为您缺少浏览器控件上的 IsScriptEnabled 属性。将此设置为 true 以启用 Javascript。http://msdn.microsoft.com/en-us/library/windowsphone/develop/microsoft.phone.controls.webbrowser.isscriptenabled(v=vs.105).aspx

我以前遇到过几次这个问题,这很烦人。

于 2013-10-15T08:43:28.210 回答
1

我建议使用https://www.nuget.org/packages/DropboxOAuth2Client/ (DropBoxOAuth2Client) 和https://www.nuget.org/packages/oauth2authorizer/ (oAuth2Authorizer) NuGet 包。oAuth2Authorizer 对于获取访问令牌很有用。一旦获得访问令牌,就可以使用 DropBoxClient,它是任何 .NET 客户端的 REST API 的简单包装器。

于 2013-10-28T08:31:22.537 回答