使用Google Apps脚本使用People API更新Google联系人照片

时间:2020-01-30 08:01:30

标签: google-apps-script google-contacts-api google-people google-people-api

我想使用People API和google apps脚本更新联系人的联系人照片。官方文档URL在https://developers.google.com/people/api/rest/v1/people/updateContactPhoto

我的Google Apps脚本代码如下

function imageUpdate(){
  var id = 'c6379259805458445151'
  var url = 'https://admin.singlaapparels.com/Main/fileurl/64F619B8-C2BE-4EDF-BF9B-01FD60C5D957/4/RakeshKumar.jpg'
  var blob = UrlFetchApp.fetch(url).getBlob();
  var data = Utilities.base64EncodeWebSafe(blob.getBytes());
  var resourceName = 'people/'+id;
  Logger.log(data)
  var reqBody = {
    "photoBytes": data,
    "personFields": "photos"
  }
var res = People.People.updateContactPhoto(resourceName, reqBody)
Logger.log(res)   
}

我收到此错误:对people.people.updateContactPhoto的API调用失败,并显示错误:空响应

1 个答案:

答案 0 :(得分:2)

我更改了参数的位置,对我有用。

来自

var res = People.People.updateContactPhoto(resourceName, reqBody)

var res = People.People.updateContactPhoto(reqBody, resourceName)