Created
June 23, 2014 05:53
-
-
Save yemrekeskin/eba581e17998a223b38f to your computer and use it in GitHub Desktop.
Retrieving all google contacts using c#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using Google.Contacts; | |
using Google.GData.Contacts; | |
using Google.GData.Client; | |
using Google.GData.Extensions; | |
namespace GmailContactList | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
RequestSettings settings = new RequestSettings("GmailContactList","yemrekeskin@gmail.com","----"); | |
// Add authorization token. | |
// ... | |
ContactsRequest cr = new ContactsRequest(settings); | |
PrintAllContacts(cr); | |
Console.ReadLine(); | |
} | |
public static void PrintAllContacts(ContactsRequest cr) | |
{ | |
Feed<Contact> f = cr.GetContacts(); | |
foreach (Contact entry in f.Entries) | |
{ | |
if (entry.Name != null) | |
{ | |
Name name = entry.Name; | |
if (!string.IsNullOrEmpty(name.FullName)) | |
Console.WriteLine("\t\t" + name.FullName); | |
else | |
Console.WriteLine("\t\t (no full name found)"); | |
if (!string.IsNullOrEmpty(name.NamePrefix)) | |
Console.WriteLine("\t\t" + name.NamePrefix); | |
else | |
Console.WriteLine("\t\t (no name prefix found)"); | |
if (!string.IsNullOrEmpty(name.GivenName)) | |
{ | |
string givenNameToDisplay = name.GivenName; | |
if (!string.IsNullOrEmpty(name.GivenNamePhonetics)) | |
givenNameToDisplay += " (" + name.GivenNamePhonetics + ")"; | |
Console.WriteLine("\t\t" + givenNameToDisplay); | |
} | |
else | |
Console.WriteLine("\t\t (no given name found)"); | |
if (!string.IsNullOrEmpty(name.AdditionalName)) | |
{ | |
string additionalNameToDisplay = name.AdditionalName; | |
if (string.IsNullOrEmpty(name.AdditionalNamePhonetics)) | |
additionalNameToDisplay += " (" + name.AdditionalNamePhonetics + ")"; | |
Console.WriteLine("\t\t" + additionalNameToDisplay); | |
} | |
else | |
Console.WriteLine("\t\t (no additional name found)"); | |
if (!string.IsNullOrEmpty(name.FamilyName)) | |
{ | |
string familyNameToDisplay = name.FamilyName; | |
if (!string.IsNullOrEmpty(name.FamilyNamePhonetics)) | |
familyNameToDisplay += " (" + name.FamilyNamePhonetics + ")"; | |
Console.WriteLine("\t\t" + familyNameToDisplay); | |
} | |
else | |
Console.WriteLine("\t\t (no family name found)"); | |
if (!string.IsNullOrEmpty(name.NameSuffix)) | |
Console.WriteLine("\t\t" + name.NameSuffix); | |
else | |
Console.WriteLine("\t\t (no name suffix found)"); | |
} | |
else | |
Console.WriteLine("\t (no name found)"); | |
foreach (EMail email in entry.Emails) | |
{ | |
Console.WriteLine("\t" + email.Address); | |
} | |
} | |
Console.WriteLine("Contact Count : {0}",f.TotalResults); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment