locked
Insert/edit/delete google contact through asp.net RRS feed

  • Question

  • User-923738156 posted

    Hi

    I want insert/edit/delete my google contact through my asp.net web application, please provide the steps for integration

    Monday, July 11, 2016 5:21 AM

All replies

  • User-821857111 posted

    You should start here: https://developers.google.com/google-apps/contacts/v3/

    Monday, July 11, 2016 7:05 AM
  • User-923738156 posted

    Hi Mike

         I already try that one, can you please explain the step by step because its my first task with google api so i can't able to do this. please help on this.

    Monday, July 11, 2016 7:11 AM
  • User-821857111 posted

    Instead of asking people to do your work for you, perhaps you should explain exactly what you tried and what errors you got or in what way it didn't work. It might be a lot quicker for someone to fix a typo in your existing code rather than start from scratch.

    Monday, July 11, 2016 8:11 AM
  • User-923738156 posted

    Thank you mike for responding us

    I used following code for insert google contact in button click event

    RequestSettings settings = new RequestSettings("computerdoctor");
                ContactsRequest cr = new ContactsRequest(settings);

                Contact newEntry = new Contact();
                // Set the contact's name.
                newEntry.Name = new Name()
                    {
                        FullName = txtfirst_name.Text,
                        GivenName = txtlast_time.Text,
                        FamilyName = txtfirst_name.Text + " " + txtlast_time.Text,
                    };
                newEntry.Content = "Notes";
                // Set the contact's e-mail addresses.
                newEntry.Emails.Add(new EMail()
                    {
                        Primary = true,
                        Rel = ContactsRelationships.IsHome,
                        Address = "brajasmec@gmail.com"
                    });
                newEntry.Emails.Add(new EMail()
                    {
                        Rel = ContactsRelationships.IsWork,
                        Address = "rajasekar.b@pickzy.com"
                    });
                // Set the contact's phone numbers.
                newEntry.Phonenumbers.Add(new PhoneNumber()
                    {
                        Primary = true,
                        Rel = ContactsRelationships.IsWork,
                        Value = txtcontact_no.Text,
                    });
                
                // Set the contact's IM information.
                newEntry.IMs.Add(new IMAddress()
                    {
                        Primary = true,
                        Rel = ContactsRelationships.IsHome,
                        Protocol = ContactsProtocols.IsGoogleTalk,
                    });
                // Set the contact's postal address.
                newEntry.PostalAddresses.Add(new StructuredPostalAddress()
                    {
                        Rel = ContactsRelationships.IsWork,
                        Primary = true,
                        Street = txt_addr1.Text,
                        City = txt_addr2.Text,
                        Region = txtlocation.Text,
                        Postcode = txtzipcode.Text,
                        Country = txt_country.Text,
                        FormattedAddress = txt_addr1.Text + " " + txt_addr2.Text + " " + txtlocation.Text + " " + txtzipcode.Text + " " + txt_country.Text,
                    });
                // Insert the contact.
                Uri feedUri = new Uri(ContactsQuery.CreateContactsUri("default"));
                Contact createdEntry = cr.Insert(feedUri, newEntry);

    but it throws error on last line "Contact createdEntry = cr.Insert(feedUri, newEntry);"

    The remote server returned an error: (401) Unauthorized.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Net.WebException: The remote server returned an error: (401) Unauthorized.

    Source Error:

    Line 226:            // Insert the contact.
    Line 227:            Uri feedUri = new Uri(ContactsQuery.CreateContactsUri("default"));
    Line 228:            Contact createdEntry = cr.Insert(feedUri, newEntry);
    Line 229:
    Line 230:

    Monday, July 11, 2016 9:05 AM
  • User-821857111 posted

    The remote server returned an error: (401) Unauthorized.
    You need to read the section titled "Authorizing requests with OAuth 2.0" on the page I linked to.

    Monday, July 11, 2016 9:48 AM
  • User-923738156 posted

    I got your point mike but I am having all the credentials for google contact api, actually my problem was I don't know where to use that in my code can you please help on that

    Thank you & Regards

    Rajasekar

    Monday, July 11, 2016 10:08 AM