Click here to Skip to main content
12,359,102 members (41,520 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET
hi,I am using Google API 2.0 for imports contacts from my web application.It's working in local but it's not working in live ( after server hosting) causing error is invalid credentials.below my code is here .give me a good solution.Advance thanks
public class GoogleContactService
{
    public static ContactsService GContactService = null;
    
    public static void InitializeService(string username,
    string password)
    {
        
        GContactService = new ContactsService("Contact Infomation");
 
        GContactService.setUserCredentials(username, password);
    }
 
    public static List<ContactDetail> GetAllContact()
    {
        List<ContactDetail> contactDetails = new List<ContactDetail>();
        ContactsQuery query = new ContactsQuery(ContactsQuery.
        CreateContactsUri("default"));
 
        ContactsFeed feed = GContactService.Query(query);
        foreach (ContactEntry entry in feed.Entries)
        {
            ContactDetail contact = new
            ContactDetail
            {
                Name = entry.Title.Text,
                EmailAddress1 = entry.Emails.Count >= 1 ? entry.Emails[0].Address : "",
                EmailAddress2 = entry.Emails.Count >= 2 ? entry.Emails[1].Address : "",
                Phone = entry.Phonenumbers.Count >= 1 ? entry.Phonenumbers[0].Value : "",
                Address = entry.PostalAddresses.Count >= 1 ? entry.PostalAddresses[0].Value : "",
                Details = entry.Content.Content
            };
 
            contactDetails.Add(contact);
        }
 
        return contactDetails;
    }
 
    public static void AddContact(ContactDetail contact)
    {
        ContactEntry newEntry = new ContactEntry();
        newEntry.Title.Text = contact.Name;
 
        EMail primaryEmail = new EMail(contact.EmailAddress1);
        primaryEmail.Primary = true;
        primaryEmail.Rel = ContactsRelationships.IsWork;
        newEntry.Emails.Add(primaryEmail);
 
        EMail secondaryEmail = new EMail(contact.EmailAddress2);
        secondaryEmail.Rel = ContactsRelationships.IsHome;
        newEntry.Emails.Add(secondaryEmail);
 
        PhoneNumber phoneNumber = new PhoneNumber(contact.Phone);
        phoneNumber.Primary = true;
        phoneNumber.Rel = ContactsRelationships.IsMobile;
        newEntry.Phonenumbers.Add(phoneNumber);
 
        PostalAddress postalAddress = new PostalAddress();
        postalAddress.Value = contact.Address;
        postalAddress.Primary = true;
        postalAddress.Rel = ContactsRelationships.IsHome;
        newEntry.PostalAddresses.Add(postalAddress);
 
        newEntry.Content.Content = contact.Details;
 
        Uri feedUri = new Uri(ContactsQuery.CreateContactsUri("default"));
 
        ContactEntry createdEntry = (ContactEntry)GContactService.Insert(feedUri, newEntry);
    }
}
 
public class ContactDetail
{
    public string Name { get; set; }
    public string EmailAddress1 { get; set; }
    public string EmailAddress2 { get; set; }
    public string Phone { get; set; }
    public string Address { get; set; }
    public string Details { get; set; }
}
Posted 7-Dec-12 20:10pm
Vasim8892.3K

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 8 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100