1

I'm trying to delete Google contacts using their customer ID as mentioned in Google Contacts API version 3.0. https://developers.google.com/google-apps/contacts/v3/#deleting_contacts

Here is the code after authentication:

    $.ajax({
    url:"https://www.google.com/m8/feeds/contacts/{emailid}/full/{usercontactId}?access_token=" + token.access_token,
        headers: {
             "Content-Type": "application/json",
            'If-Match': '*',
            'Gdata-version': '3.0'
        },
         dataType: 'jsonp',
        data: {},
        success: function (output) {
            console.log(output)
        }

    }); 

I have given the correct "access_token", "emailID" and "usercontactId".

Please let me know the issue in the above code.

Zooly
  • 4,736
  • 4
  • 34
  • 54
  • 1
    are you setting the HTTP method to DELETE? This looks like a GET request. – Blake O'Hare Jun 26 '17 at 15:42
  • Yes, I have added in the above code "method : 'DELETE'". Like the following one. "$.ajax({method : 'DELETE',url:"https://www.google.com....." but I got only the details of the particular contact. I think my code is wrong. Please advice. – Vinoth Kumar Jun 26 '17 at 19:05

2 Answers2

1

You must use the DELETE HTTP method to execute this.

The access_token should be in headers of your request.

Your URL should contain:

URL: https://www.google.com/m8/feeds/contacts/default/full/{contactID}

Headers: "GData-Version": "3.0", "Authorization":"Bearer " + token.accesstoken, "if-match":"*"

You don't need to pass data to a delete request, or even content-type.

Zooly
  • 4,736
  • 4
  • 34
  • 54
  • Thank you for the answer. Now I got this error. XMLHttpRequest cannot load https://www.google.com/m8/feeds/contacts/default/full/xxxxxxxx. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'mysite.com' is therefore not allowed access. The response had HTTP status code 405. Please let me know the issue. – Vinoth Kumar Jun 27 '17 at 19:20
  • How are you calling your request ? – Zooly Jun 27 '17 at 23:23
  • 1
    Here is the code I have used. I have checked I am using the correct accesstoken value. $.ajax({ method : 'DELETE', url: "https://www.google.com/m8/feeds/contacts/default/full/18efa588a46dd9 ", headers: { "GData-Version": "3.0", "Authorization":"Bearer " + token.accesstoken, "if-match":"*" }, success: function (output) { console.log(output) } }); Please let me know the issue. Also in the API manager "Authorized JavaScript origins" I have added the website name. – Vinoth Kumar Jun 28 '17 at 02:40
  • https://stackoverflow.com/questions/43389224/405-error-with-post-request-angularjs-http – Zooly Jun 28 '17 at 07:19
-1

You may refer with this thread. Try to use the google client api for javascript. Authenticate, getToken, use Request and then execute it.

For delete purpose, pass these as its input:

method : 'DELETE',
url : '/m8/feeds/contacts/default/full/<friend id to delete>'

Hope this helps!

abielita
  • 13,147
  • 2
  • 17
  • 59