Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing gmail contacs using Oauth2 #717

Open
GoogleCodeExporter opened this issue Feb 25, 2016 · 0 comments
Open

Importing gmail contacs using Oauth2 #717

GoogleCodeExporter opened this issue Feb 25, 2016 · 0 comments

Comments

@GoogleCodeExporter
Copy link

Please FInd the below Code .. m getting exception" Execution of authentication 
request returned unexpected result: 404 "
please help me to fix it 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Google.GData.Extensions.Apps;
using Google.GData.Client;
using Google.Contacts;
public partial class _Default : System.Web.UI.Page
{
    private static string clientId;
    private static string clientSecret;
    private static string domain;

    private static string applicationName = "Test-OAuth2";

    // Installed (non-web) application
    private static string redirectUri = "http://localhost:51598/WebSite1/Default2.aspx" ;

    // Requesting access to Contacts API and Groups Provisioning API
    private static string scopes = "https://www.google.com/m8/feeds/";

    protected void Page_Load(object sender, EventArgs e)
    {
        clientId = "51382749591-acdara9kbhlrvo529ivnhbigsvd0m0rb.apps.googleusercontent.com";
        clientSecret = "IZGxIUoGpGjBqYFqDpNabicv";
        domain = "";

        OAuth2Parameters parameters = new OAuth2Parameters()
        {
            ClientId = clientId,
            ClientSecret = clientSecret,
            RedirectUri = redirectUri,
            Scope = scopes
        };

        string url = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters);
        Console.WriteLine("Authorize URI: " + url);
        parameters.AccessCode = Console.ReadLine();

        OAuthUtil.GetAccessToken(parameters);

        // Testing OAuth 2.0 with a Request-based library
        RunContactsSample(parameters);


    }
    private static void RunContactsSample(OAuth2Parameters parameters)
    {
        try
        {
            RequestSettings settings = new RequestSettings(applicationName, parameters);
            ContactsRequest cr = new ContactsRequest(settings);

            Feed<Contact> f = cr.GetContacts();
            foreach (Contact c in f.Entries)
            {
                Console.WriteLine(c.Name.FullName);
            }
        }
        catch (Exception a)
        {
            Console.WriteLine("A Google Apps error occurred.");
            Console.WriteLine();
            //Console.WriteLine("Error code: {0}", a.ErrorCode);
            //Console.WriteLine("Invalid input: {0}", a.InvalidInput);
            //Console.WriteLine("Reason: {0}", a.Reason);
        }
    }
}




Original issue reported on code.google.com by [email protected] on 30 May 2015 at 6:17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant