问题
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