简体   繁体   中英

Google Access on WP7

I am having problems building an app that can access google accounts. I have the following code that gets the sign in 登录页面 page for google accounts and then the access permissions page is also displayed! 在此处输入图片说明 . Once i click on "Allow Access" the app is redirected to error page 错误 . here are few screenshots so that whoever is trying to help can understand better.. and below is the code that am using

 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=en_GB&xsrfsign=APsBz4gAAAAAUHZvwB3xTqisyv8hEcWem5X3eKvwAHN9 this is the URI its navigating to after allow access is selected/clicked. What does this mean?

This is all am doing. My BrowserNavigated Method doesn't contain any code as of now. I dunno what to do further.hence seeking help. Please help me resolve this issue.. All answers and suggestion appreciated.

Just check the GDrive open-source application code here .

The Authorization View and ViewModel show you how you can make OAuth sign-in with Google credentials.

Download the code, read the pre-build instructions on the site, and test it!

 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);

        }
    }

The XAML goes like this

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

My mistakes were two:- 1) as vignesh has mentioned in his comments I was using a wrong Redirect URI. 2)IsScriptEnabled was not at all set in my Web Browser Controls. Once i set it true everything was fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM