繁体   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