0

DropNet を使用して Windows Phone 8 アプリを Dropbox に接続しようとしています。残念ながらほとんど成功していません。

DropNet Git ページの例とドキュメントに従って、アプリを Dropbox に接続する 2 つの異なる方法を試しました。

1 つ目は、DropNet Git ページに直接表示される「クラシック」ソリューションです。RequestToken を取得した後、内部 WebBrowser コントロールを使用して Dropbox ログイン ページに移動します。しかし、私はこれを機能させることができませんでした。トークンとリクエスト URL の生成は問題ありません。しかし、ページは WebBrowser コントロールに正しく読み込まれません。コントロールはちらつきますが、コンテンツは表示されません。他のページ (Google など) に移動すると、コントロールは正しく機能します。

2 番目のソリューションは、ほとんど同じように機能します。WebBrowser コントロールを使用する代わりに、URL が直接呼び出されるため、Browser App のビルドが使用されます。これは問題なく動作します。ログインが完了すると、ユーザーはカスタム 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