Google Photos API:400要求更新MediaItem说明的错误
我正在尝试在我的Google Photos库中“修补”(更新)MEVERITEM,以设置新的描述并遇到意外的400错误。我指的是 /photos/library/guides/manage-media#greats_media_item_descriptions 有关如何做的。我在Google Apps脚本项目中写作,其他API呼叫工作正常,喜欢在专辑中列出专辑和列表MediaItems。许可范围为https://www.googleapis.com/auth/photoslibrary.readonly https://www.googleapis.com/auth/photoslibrary.edit.edit.appcreatededdata
。
这是我的代码的样子:
// thisMediaItem is a media item returned from a previous call
var id = thisMediaItem.id;
Logger.log("Here is the full JSON for the media item " + id);
Logger.log(JSON.stringify(thisMediaItem));
// now try "patching" the media item with a new description
var url = 'https://photoslibrary.googleapis.com/v1/mediaItems/' + id + "?updateMask=description";
var response = UrlFetchApp.fetch(url, {
headers: { Authorization: 'Bearer ' + photoService.getAccessToken() },
muteHttpExceptions: true,
method: "patch",
payload: { "description": "my new description" }
});
Logger.log(response.getContentText());
这是我在日志中得到的,尽管我确实将其包含在有效载荷中,但找不到描述字段。我尝试从会员名称中删除引号,但仍然不起作用。
5:12:24 PM Info Here is the full JSON for the media item AHndD0EfrVXtMUHxuCOT3V81D6ZUr8YkRz3a6PvZE6k8PCF9pMCh4gxj1IHxkVVrkpVnpQ12x5J9nznJICJ7ciDOtQbn2hJ6DA
5:12:24 PM Info {"id":"AHndD0EfrVXtMUHxuCOT3V81D6ZUr8YkRz3a6PvZE6k8PCF9pMCh4gxj1IHxkVVrkpVnpQ12x5J9nznJICJ7ciDOtQbn2hJ6DA","description":"lake","productUrl":"https://photos.google.com/lr/album/AHndD0FrK2VQxeFhlCuOrJFV-C8YrwjI_eM2nFnBTuVh_S1QerqpNOFoS8o2X0tz7Xh_DJLnH68s/photo/AHndD0EfrVXtMUHxuCOT3V81D6ZUr8YkRz3a6PvZE6k8PCF9pMCh4gxj1IHxkVVrkpVnpQ12x5J9nznJICJ7ciDOtQbn2hJ6DA","baseUrl":"https://lh3.googleusercontent.com/lr/AFBm1_bpo-9VZkKEUKVmLGwZifhWZe_18r5R1eWh53o5YghfnyFH11JOFSU3L_6gc6h5xktjE7qHKAYtBX5yEQoEOhkGfxFQjmKcHXUa52QBUjg2jMvyyIpoVjP27fYP5GPUEUn7ncADwqLeTSKBbIF-sGZuKt2QBaYNR3a3icFxBUz8x2mC_PIU6SsKWeVrKTO8v6yx84GjfSN3XbDlmRKLdAiZ7OpBXk6TP4pLEVONrkEKGpX_cy_-1AEejEF3hQNgqxwlPmtzrbiRJIO25gfCLANEdxMVt_LjmM5Avb0TiZTZ2SdUrUMWQNA0YAGH6D7KE79CTF34jKfui_EM5_eslwujqRwwoh_l6oorsCqMyVHjHqqfQ2QIPEa3VepucQD5RiIWXEImXSQaxkChz0CF-KB7u9vuj-sS8TJB2CefsHuhNiyq0owvEB8swZM07RpWKm1-4mlS286uCKgfPOeNWyWJETOWs9u1GJHCVH4N1zj2MhxSaGjAHD-3H9OgcIIK56mBJiNjLmOCJY_uTMz-tJ8INdBSp8vv979bREzXfcB23s7dvrz11sjvi7YcVRRDRchq0kEuyuXoC87QyY0YBt-QlSmcU7yXZEQ_ZwZsTzQJXawtMCffDYumUCjBCcx3mrlahGTHNGmjsWDm5SHi3eolC6rBWxno1B2S_2Z-5_vjHfbLMTyIzEmg6YuB__0vIdyaY4E5DNavqL7AF-y4T79eKru9bCXgGUDeBb52qySsAJHny14tofcWdu0bc0fwXjAFH1ZxwRbQTIXPXz1uHPea81ksZai-zGzcax6WOC-0awE0IEWCq5NB2goplxmrMLReHO_nT1L1cQ","mimeType":"image/jpeg","mediaMetadata":{"creationTime":"1966-01-01T20:00:26Z","width":"2640","height":"1778","photo":{"cameraMake":"Nikon","cameraModel":"LS-5000"}},"filename":"slide0011.jpg"}
5:12:24 PM Info {
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"description\": Cannot bind query parameter. Field 'description' could not be found in request message.",
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"description": "Invalid JSON payload received. Unknown name \"description\": Cannot bind query parameter. Field 'description' could not be found in request message."
}
]
}
]
}
}
I am trying to "patch" (update) a mediaItem in my Google Photos library to set a new description and am getting an unexpected 400 error. I am referring to the article at https://developers.google.com/photos/library/guides/manage-media#changing_media_item_descriptions for how to do it. I am writing in a Google Apps Script project and other API calls are working fine, like to list albums and list mediaItems inside albums. Permission scopes are https://www.googleapis.com/auth/photoslibrary.readonly https://www.googleapis.com/auth/photoslibrary.edit.appcreateddata
.
Here is what my code looks like:
// thisMediaItem is a media item returned from a previous call
var id = thisMediaItem.id;
Logger.log("Here is the full JSON for the media item " + id);
Logger.log(JSON.stringify(thisMediaItem));
// now try "patching" the media item with a new description
var url = 'https://photoslibrary.googleapis.com/v1/mediaItems/' + id + "?updateMask=description";
var response = UrlFetchApp.fetch(url, {
headers: { Authorization: 'Bearer ' + photoService.getAccessToken() },
muteHttpExceptions: true,
method: "patch",
payload: { "description": "my new description" }
});
Logger.log(response.getContentText());
And here is what I get in the logs, something about the description field not found, although I did include it in the payload. I have tried removing quotes from the member name and it still doesn't work.
5:12:24 PM Info Here is the full JSON for the media item AHndD0EfrVXtMUHxuCOT3V81D6ZUr8YkRz3a6PvZE6k8PCF9pMCh4gxj1IHxkVVrkpVnpQ12x5J9nznJICJ7ciDOtQbn2hJ6DA
5:12:24 PM Info {"id":"AHndD0EfrVXtMUHxuCOT3V81D6ZUr8YkRz3a6PvZE6k8PCF9pMCh4gxj1IHxkVVrkpVnpQ12x5J9nznJICJ7ciDOtQbn2hJ6DA","description":"lake","productUrl":"https://photos.google.com/lr/album/AHndD0FrK2VQxeFhlCuOrJFV-C8YrwjI_eM2nFnBTuVh_S1QerqpNOFoS8o2X0tz7Xh_DJLnH68s/photo/AHndD0EfrVXtMUHxuCOT3V81D6ZUr8YkRz3a6PvZE6k8PCF9pMCh4gxj1IHxkVVrkpVnpQ12x5J9nznJICJ7ciDOtQbn2hJ6DA","baseUrl":"https://lh3.googleusercontent.com/lr/AFBm1_bpo-9VZkKEUKVmLGwZifhWZe_18r5R1eWh53o5YghfnyFH11JOFSU3L_6gc6h5xktjE7qHKAYtBX5yEQoEOhkGfxFQjmKcHXUa52QBUjg2jMvyyIpoVjP27fYP5GPUEUn7ncADwqLeTSKBbIF-sGZuKt2QBaYNR3a3icFxBUz8x2mC_PIU6SsKWeVrKTO8v6yx84GjfSN3XbDlmRKLdAiZ7OpBXk6TP4pLEVONrkEKGpX_cy_-1AEejEF3hQNgqxwlPmtzrbiRJIO25gfCLANEdxMVt_LjmM5Avb0TiZTZ2SdUrUMWQNA0YAGH6D7KE79CTF34jKfui_EM5_eslwujqRwwoh_l6oorsCqMyVHjHqqfQ2QIPEa3VepucQD5RiIWXEImXSQaxkChz0CF-KB7u9vuj-sS8TJB2CefsHuhNiyq0owvEB8swZM07RpWKm1-4mlS286uCKgfPOeNWyWJETOWs9u1GJHCVH4N1zj2MhxSaGjAHD-3H9OgcIIK56mBJiNjLmOCJY_uTMz-tJ8INdBSp8vv979bREzXfcB23s7dvrz11sjvi7YcVRRDRchq0kEuyuXoC87QyY0YBt-QlSmcU7yXZEQ_ZwZsTzQJXawtMCffDYumUCjBCcx3mrlahGTHNGmjsWDm5SHi3eolC6rBWxno1B2S_2Z-5_vjHfbLMTyIzEmg6YuB__0vIdyaY4E5DNavqL7AF-y4T79eKru9bCXgGUDeBb52qySsAJHny14tofcWdu0bc0fwXjAFH1ZxwRbQTIXPXz1uHPea81ksZai-zGzcax6WOC-0awE0IEWCq5NB2goplxmrMLReHO_nT1L1cQ","mimeType":"image/jpeg","mediaMetadata":{"creationTime":"1966-01-01T20:00:26Z","width":"2640","height":"1778","photo":{"cameraMake":"Nikon","cameraModel":"LS-5000"}},"filename":"slide0011.jpg"}
5:12:24 PM Info {
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"description\": Cannot bind query parameter. Field 'description' could not be found in request message.",
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"description": "Invalid JSON payload received. Unknown name \"description\": Cannot bind query parameter. Field 'description' could not be found in request message."
}
]
}
]
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的脚本中,请按以下方式修改它。
来自:
至:
注意:
参考:
In your script, please modify it as follows.
From:
To:
Note:
Reference: