Adding/updating a Google Contact's photo

故事扮演 提交于 2021-01-28 11:38:48

问题


I am trying to update a Google Contacts contact's photo via URL using Google Apps Script.

The below is my attempt.

function addContactPhoto (blob) {
  var image = UrlFetchApp.fetch("http://www.example.com/joe_bloggs.png");
  var options = {
   'method' : 'put',
   'contentType': 'image/png',
   'payload' : image.getBlob()
 };
UrlFetchApp.fetch('https://www.google.com/m8/feeds/photos/media/{userEmail}/{contactID}', options);
}

I was trying to follow the instructions for the Google Contacts API by sending a PUT request to https://www.google.com/m8/feeds/photos/media/{userEmail}/{contactID} with the image as a Blob object in the payload.

Is this approach correct? I am having problems with getting the image URL being converted to the right object to be send through the URL. I would also like help with inserting the correct values of userEmail and contactID.


回答1:


For the payload, use image.getBlob().getBytes() for the correct image type.

You'll also need to use OAuth2 for sending put requests. Add the line

options.headers = {
    Authorization: 'Bearer ' + yourAccessToken
};

after you declare your options.



来源:https://stackoverflow.com/questions/49418889/adding-updating-a-google-contacts-photo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!