3

Web 認証サンプルを使用して Google にサインインできます。コードは次のとおりです。

    private async void Launch_Click(object sender, RoutedEventArgs e) 
    {    
        if(GoogleClientID.Text == "") 
        { 
            rootPage.NotifyUser("Please enter an Client ID.", NotifyType.StatusMessage); 
        } 
        else if(GoogleCallbackUrl.Text == "") 
        { 
            rootPage.NotifyUser("Please enter an Callback URL.", NotifyType.StatusMessage); 
        } 

        try 
        { 
            String GoogleURL = "https://accounts.google.com/o/oauth2/auth?client_id=" + Uri.EscapeDataString(GoogleClientID.Text) + "&redirect_uri=" + Uri.EscapeDataString(GoogleCallbackUrl.Text) + "&response_type=code&scope=" + Uri.EscapeDataString("http://picasaweb.google.com/data"); 

            System.Uri StartUri = new Uri(GoogleURL); 
            // When using the desktop flow, the success code is displayed in the html title of this end uri 
            System.Uri EndUri = new Uri("https://accounts.google.com/o/oauth2/approval?"); 

            DebugPrint("Navigating to: " + GoogleURL); 

            WebAuthenticationResult WebAuthenticationResult = await WebAuthenticationBroker.AuthenticateAsync( 
                                                    WebAuthenticationOptions.UseTitle, 
                                                    StartUri, 
                                                    EndUri); 
            if (WebAuthenticationResult.ResponseStatus == WebAuthenticationStatus.Success) 
            { 
                OutputToken(WebAuthenticationResult.ResponseData.ToString()); 
            } 
            else if (WebAuthenticationResult.ResponseStatus == WebAuthenticationStatus.ErrorHttp) 
            { 
                OutputToken("HTTP Error returned by AuthenticateAsync() : " + WebAuthenticationResult.ResponseErrorDetail.ToString()); 
            } 
            else 
            { 
                OutputToken("Error returned by AuthenticateAsync() : " + WebAuthenticationResult.ResponseStatus.ToString()); 
            } 
        } 
        catch (Exception Error) 
        { 
            // 
            // Bad Parameter, SSL/TLS Errors and Network Unavailable errors are to be handled here. 
            // 
            DebugPrint(Error.ToString()); 
        } 
}       

アプリが認証された後、ファイル操作を使用する方法がわかりません。それらは、Google が利用できるようにした .Net ライブラリですが、Windows ストア アプリでは機能しないようです。

以下は、http 経由のドキュメント アップロード ファイルです。

Google ドライブ API: https://developers.google.com/drive/manage-uploads

HttpClient サンプルを使用してみましたが、認証サンプルから取得した認証トークンの使用方法がわかりませんでした。

4

1 に答える 1