0

I have Used a API for importing the contacts of GMail. The code is something like this:

public static DataTable GetGmailContacts(string App_Name, string Uname, string UPassword)
    {
        Log.LogDebug(string.Format("SettingsController.cs-Importing Contacts for email={0}, password={1} from gmail server", Uname, UPassword));
        DataTable dt = new DataTable();
        DataColumn C2 = new DataColumn();
        C2.DataType = Type.GetType("System.String");
        C2.ColumnName = "EmailID";
        try
        {
            dt.Columns.Add(C2);
            RequestSettings rs = new RequestSettings(App_Name, Uname, UPassword);
            rs.AutoPaging = true;
            ContactsRequest cr = new ContactsRequest(rs);
            Feed<Contact> f = cr.GetContacts();
            foreach (Contact t in f.Entries)
            {
                foreach (EMail email in t.Emails)
                {
                    DataRow dr1 = dt.NewRow();
                    dr1["EmailID"] = email.Address.ToString();
                    dt.Rows.Add(dr1);
                }
            }
            Log.LogDebug(string.Format("SettingsController.cs-Imported Contacts for email={0}, password={1} from gmail server", Uname, UPassword));
            return dt;
        }
        catch (Exception e)
        {
            dt = null;
            Log.LogDebug(string.Format("SettingsController.cs-Imported Contacts for email={0}, password={1} from gmail server", Uname, UPassword));
            return dt;
        }
    }

This code importing the GMail contacts but it is third party DLL. So some time Google warned me to not use it. So I want to use Direct API.

tereško
  • 58,060
  • 25
  • 98
  • 150
Himanhu_cool
  • 33
  • 1
  • 1
  • 6

1 Answers1

0

Versions 1 and 2 of the Google Contacts API have been officially deprecated as of April 20, 2012. They will continue to work as per our deprecation policy, but we encourage you to move to version 3
From: https://developers.google.com/google-apps/contacts/v2/developers_guide?hl=en

Authorizing requests with OAuth 2.0

Requests to the Google Contacts API for non-public user data must be authorized by an authenticated user.

The details of the authorization process, or "flow," for OAuth 2.0 vary somewhat depending on what kind of application you're writing. The following general process applies to all application types:

  1. When you create your application, you register it with Google. Google then provides information you'll need later, such as a client ID and a client secret.
  2. Activate the Google Contacts API in the Services pane of the Google APIs Console. (If it isn't listed in the Console, then skip this step.)
  3. When your application needs access to user data, it asks Google for a particular scope of access.
  4. Google displays an OAuth dialog to the user, asking them to authorize your application to request some of their data.
  5. If the user approves, then Google gives your application a short-lived access token.
  6. Your application requests user data, attaching the access token to the request.
  7. If Google determines that your request and the token are valid, it returns the requested data.

From: https://developers.google.com/google-apps/contacts/v3/#authorizing_requests_with_oauth_20

Check Google Contacts API v2 Developer's Guide - .Net and Google Contacts API version 3.0 to write your own code :)

Amirhossein Mehrvarzi
  • 18,024
  • 7
  • 45
  • 70