簡體   English   中英

WP7上的Google Access

[英]Google Access on WP7

我在構建可以訪問Google帳戶的應用程序時遇到問題。 我有以下代碼可以登錄 登錄頁面 google帳戶頁面,然后還會顯示訪問權限頁面! 在此處輸入圖片說明 一旦我單擊“允許訪問”,該應用程序將重定向到錯誤頁面 錯誤 這是一些屏幕截圖,以便任何試圖提供幫助的人都可以更好地了解..下面是正在使用的代碼

 private void browseGoogle_Loaded(object sender, RoutedEventArgs e)
    {
        string address = "https://accounts.google.com/o/oauth2/auth" +
        "?client_id=" + "*******.apps.googleusercontent.com" +
        "&scope=" + "https://www.googleapis.com/auth/plus.me" +
        "&response_type=code" +
         "&redirect_uri=" + "https://www.****.com/oauth2callback";

        browseGoogle.Navigate(new Uri(address, UriKind.Absolute));

    }

https://accounts.google.com/o/oauth2/approval?as=634f855389bf10ff&hl=zh_HK&xsrfsign=APsBz4gAAAAAUHZvwB3xTqisyv8hEcWem5X3eKvwAHN9這是在選擇/單擊允許訪問后導航至的URI。 這是什么意思?

這都在做。 到目前為止,我的BrowserNavigated方法不包含任何代碼。 我不知道該怎么做。因此尋求幫助。 請幫助我解決此問題。感謝所有答案和建議。

只需在此處查看GDrive開源應用程序代碼。

Authorization ViewViewModel向您展示如何使用Google憑據進行OAuth登錄。

下載代碼,閱讀網站上的預構建說明,然后進行測試!

 private void browseGoogle_Loaded(object sender, RoutedEventArgs e)
    { 
        try
        {
            StringBuilder autheticateURL = new StringBuilder();
            autheticateURL.Append(GmailSettings.AuthorizeUri).Append("?client_id=").Append(GmailSettings.clientID).Append("&scope=").
                Append(GmailSettings.ScopeValue).Append("&response_type=code").Append("&redirect_uri=").Append(GmailSettings.CallbackUri);
            browseGoogle.Navigate(new Uri(autheticateURL.ToString(), UriKind.Absolute));
        }
        catch (Exception ex)
        {

            Logger.log(TAG, "browseGoogle_Loaded()", ex.Message);

        }
    }

    /// <summary>
    /// Called when the web browser initiates Navigation to various pages 
    /// </summary>
    /// <param name="sender">Browser</param>
    /// <param name="e">Navigating event arguments</param>
    private void browseGoogle_Navigating(object sender, NavigatingEventArgs e)
    {
        try
        {
            string hostName = e.Uri.Host;
            string URL = e.Uri.ToString();

            if (hostName.StartsWith("localhost"))
            {
                NavigationService.Navigate(new Uri("/HomePage.xaml", UriKind.Relative));
            }
        }
        catch (Exception ex)
        {

            Logger.log(TAG, "browseGoogle_Navigating()", ex.Message);

        }
    }

XAML像這樣

  <phone:WebBrowser x:Name="browseGoogle" Loaded="browseGoogle_Loaded" IsScriptEnabled="true" Navigating="browseGoogle_Navigating" />

我的錯誤有兩個:-1)正如vignesh在他的評論中提到的,我使用了錯誤的重定向URI。 2)根本沒有在我的Web瀏覽器控件中設置IsScriptEnabled。 一旦設置為true,一切都很好。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM