问题描述
我以Playground link to code为例,它看起来可以正常工作,但是联系人的照片实际上并没有改变,也没有返回错误。
我的代码
never
响应XML
const accesstoken = ScriptApp.getoAuthToken();
const id = '4c18faa28828aa3f';
const url = '-URL Omitted-';
const blob = UrlFetchApp.fetch(url).getBlob();
const data = Utilities.base64EncodeWebSafe(blob.getBytes());
const response = UrlFetchApp.fetch(`https://www.google.com/m8/Feeds/photos/media/me/${id}`,{
method: 'put',contentType: 'image/jpeg',payload: data,headers: {
Authorization: `Bearer ${accesstoken}`,},});
const content = response.getContentText();
console.log(content);
解决方法
我知道了。由于某种原因,我为有效负载编码了图像Blob字节。我应该像这样通过blob作为有效载荷。
const accessToken = ScriptApp.getOAuthToken();
const id = '4c18faa28828aa3f';
const url = '-URL Omitted-';
const blob = UrlFetchApp.fetch(url).getBlob();
const response = UrlFetchApp.fetch(`https://www.google.com/m8/feeds/photos/media/me/${id}`,{
method: 'put',contentType: 'image/jpeg',payload: blob,headers: {
Authorization: `Bearer ${accessToken}`,},});
const content = response.getContentText();
console.log(content);