我一直在尝试使用DropNet将我的Windows phone8应用程序连接到Dropbox。不幸的是,收效甚微。
根据示例和DropNet Git页面上的文档,我尝试了两种不同的方法来连接应用程序Dropbox:
第一个是直接出现在DropNet Git页面上的“经典”解决方案。获得RequestToken后,将使用一个内部WebBrowser控件导航到Dropbox Login Page。然而,我不能让它工作。生成令牌和请求URL是没有问题的。但是该页在WebBrowser控件中未正确加载。该控件只是闪烁,但不显示任何内容。当我导航到任何其他页面(如google等)时,该控件都可以正常工作。
第二种解决方案的工作原理与此基本相同。取而代之的是使用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) => {
...
});
}
}发布于 2013-10-15 16:43:28
我认为您的浏览器控件缺少IsScriptEnabled属性。将其设置为true可启用Javascript。http://msdn.microsoft.com/en-us/library/windowsphone/develop/microsoft.phone.controls.webbrowser.isscriptenabled(v=vs.105).aspx
我以前遇到过这个问题几次,它非常烦人。
发布于 2013-10-28 16:31:23
我推荐使用https://www.nuget.org/packages/DropboxOAuth2Client/ (DropBoxOAuth2Client)和https://www.nuget.org/packages/oauth2authorizer/ (oAuth2Authorizer) NuGet包。oAuth2Authorizer对于获取访问令牌很有用。一旦获得访问令牌,就可以使用DropBoxClient,它是任何.NET客户机的REST API的简单包装器。
https://stackoverflow.com/questions/19360697
复制相似问题