How to Access, Add, Update or Delete Gmail Contacts inside .NET Apps

This technical tip shows how .NET developers can access, add, update or Delete Gmail contacts inside .NET application. Aspose.Email supports working with Gmail contacts. Using the IGmailClient interface, users can retrieve contacts from a Gmail account, create new contacts, and update as well as delete existing contacts. Gmail allows developers to perform all these using its public developer's API. The following user information is required for working with Gmail contacts: User name, email address, password, client ID, client secret refresh token. This article shows how to access Gmail contacts, create new Gmail contacts, update existing contacts, delete a contact and save contact.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//your code here...Following is a sample application which can be used to access the detail of contacts in all the groups.
// C# Code Sample
 
string username = "username";
string email = "email@gmail.com";
string password = "password";
string clientId = "clientid";
string clientSecret = "client secret";
string refresh_token = "refresh token";
//The refresh_token is to be used in below.
GoogleTestUser user = new GoogleTestUser(
                username,
                email,
                password,
                clientId,     //client id
                clientSecret,     //client secret
                refresh_token);   //refresh token
using (IGmailClient client = Aspose.Email.Google.GmailClient.GetInstance(user.ClientId, user.ClientSecret, user.RefreshToken))
{
    Contact[] contacts = client.GetAllContacts();
    foreach (Contact contact in contacts)
        Console.WriteLine(contact.DisplayName + "" + contact.EmailAddresses[0]);
    //Fetch contacts from a specific group
    FeedEntryCollection groups = client.FetchAllGroups();
    GmailContactGroup group = null;
    foreach (GmailContactGroup g in groups)
        switch (g.Title)
        {
            case "TestGroup":
                group = g;
                break;
        }
    //Retrieve contacts from the Group
    if (group != null)
    {
        Contact[] contacts2 = client.GetContactsFromGroup(group);
        foreach (Contact con in contacts2)
            Console.WriteLine(con.DisplayName + "," + con.EmailAddresses[0].ToString());
    }
}
}
 
X

Url: http://www.aspose.com/docs/display/emailnet/Working+with+Gmail+contacts

Language: C# | User: Sheraz Khan | Created: Dec 17, 2014 | Tags: Access Gmail contacts Using C# Create new Gmail contacts Update existing contacts in .NET Delete a Gmail contact Save Gmail contact .NET outlook email component Aspose.Email for .NET