【问题标题】:Delete contacts using Google Contacts API with JS/jQuery使用带有 JS/jQuery 的 Google Contacts API 删除联系人
【发布时间】:2017-06-26 13:09:17
【问题描述】:

我正在尝试使用 Google 联系人 API 3.0 版中提到的客户 ID 删除 Google 联系人。 https://developers.google.com/google-apps/contacts/v3/#deleting_contacts

认证后的代码如下:

    $.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)
        }

    }); 

我给出了正确的“access_token”、“emailID”和“usercontactId”。

请让我知道上面代码中的问题。

【问题讨论】:

  • 您是否将 HTTP 方法设置为 DELETE?这看起来像一个 GET 请求。
  • 是的,我在上面的代码中添加了“方法:'DELETE'”。比如下面这个。 "$.ajax({method : 'DELETE',url:"google.com....." 但我只得到了特定联系人的详细信息。我认为我的代码有误。请指教。

标签: google-api google-contacts-api


【解决方案1】:

您必须使用DELETE HTTP 方法来执行此操作。

access_token 应该在您请求的headers 中。

您的网址应包含:

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

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

您不需要将数据传递给删除请求,甚至不需要内容类型。

【讨论】:

  • 感谢您的回答。现在我得到了这个错误。 XMLHttpRequest 无法加载 google.com/m8/feeds/contacts/default/full/xxxxxxxx。对预检请求的响应未通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,Origin 'mysite.com' 不允许访问。响应的 HTTP 状态代码为 405。请让我知道问题所在。
  • 您的请求如何?
  • 这是我使用的代码。我已经检查过我使用了正确的 accesstoken 值。 $.ajax({ method : 'DELETE', url: "google.com/m8/feeds/contacts/default/full/18efa588a46dd9 ", headers: { "GData-Version": "3.0", "Authorization":"Bearer" + token.accesstoken, "if-match": “*”},成功:函数(输出){console.log(输出)}});请让我知道这个问题。同样在 API 管理器“Authorized JavaScript origins”中,我添加了网站名称。
【解决方案2】:

您可以参考这个thread。尝试使用google client api for javascript。认证,getToken,使用Request,然后执行。

出于删除目的,将这些作为其输入传递:

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

希望这会有所帮助!

【讨论】:

  • 对不起,上面的代码不适用于我的。我将尝试使用 Google API Javascript。非常感谢。
猜你喜欢
  • 2016-10-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-13
  • 2013-09-25
  • 2017-02-11
相关资源
最近更新 更多