Google照片返回“错误400:请求包含无效的媒体项目ID.(INVALID_ARGUMENT)";将媒体项目添加到现有专辑时 [英] Google Photo returns "error 400: Request contains an invalid media item id. (INVALID_ARGUMENT)" when adding a media item into an existing album

查看:109
本文介绍了Google照片返回“错误400:请求包含无效的媒体项目ID.(INVALID_ARGUMENT)";将媒体项目添加到现有专辑时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google相册获得媒体项目列表和相册列表之后API (使用Go和Google Photo REST API),将项目添加到相册会返回错误.

After getting a list of media items and a list of albums from the Google Photo API (using Go and the Google Photo REST API), adding items to an album returns an error.

(注意:使用网络界面将项目添加到相册可以正常工作).

(Note: using the web interface to add the items to the album works fine).

将媒体项目添加到相册的代码:

Code to add the media item to the album:

func (a Album) AddItems(items ...MediaItem) error {
    rel := &url.URL{Path: fmt.Sprintf("/v1/albums/%s:batchAddMediaItems", a.ID)}
    u := a.service.baseURL.ResolveReference(rel)
    for len(items) > 0 {
        ids := []string{}
        for i := 0; i < 50 && i < len(items); i++ {
            ids = append(ids, items[i].ID)
        }
        items = items[len(ids):]
        toAdd := map[string]interface{}{
            "mediaItemIds": ids,
        }
        bodyData, err := json.Marshal(toAdd)
        if err != nil {
            return err
        }
        req, err := http.NewRequest("POST", u.String(), bytes.NewBuffer(bodyData))
        if err != nil {
            return err
        }
        resp, err := a.service.client.Do(req)
        if err != nil {
            return err
        }
        defer resp.Body.Close()
        respErr := struct {
            Error ServerError `json:"error"`
        }{}
        body, err := ioutil.ReadAll(resp.Body)
        if err != nil {
            return err
        }
        err = json.Unmarshal(body, &respErr)
        if err != nil {
            return err
        }
        err = respErr.Error.Error()
        if err != nil {
            return err
        }
    }
    return nil
}

服务器返回以下错误:

error 400: Request contains an invalid media item id. (INVALID_ARGUMENT). 

将从 a返回的媒体项目的> JSON表示搜索请求.媒体项目的其他字段似乎有效(例如ProductURL).

The media item ID is copied from the ID field of the JSON representation of a media item returned from a search request. The other fields of the media item seem to be valid (e.g. the ProductURL).

batchAddMediaItems 请求有什么问题?或如何获取适合 batchAddMediaItems 的有效媒体项目ID?

What is wrong in this batchAddMediaItems request? or how to get a valid media item ID suitable for batchAddMediaItems ?

谢谢.

推荐答案

根据指南(

According to the guide (https://developers.google.com/photos/library/guides/manage-albums), unfortunately, you can only add media items that have been uploaded by your application to albums that your application has created. Media items must also be in the user's library.

这是Issuetracker上用于组织现有媒体项目的功能请求( https://issuetracker.google.com/issues/109505022 ),但开发人员只允许使用该应用的照片/相册.但是,现在已经存在有关我们的问题的新功能要求,因此让我们一起注视一下( https://issuetracker.google.com/issues/132274769 )

It was the feature request on issuetracker for the organising existing mediaitems (https://issuetracker.google.com/issues/109505022), but developers allow only working with app's photo/album. But now it exist the new feature request about exactly our problem, so lets star it together (https://issuetracker.google.com/issues/132274769)

这篇关于Google照片返回“错误400:请求包含无效的媒体项目ID.(INVALID_ARGUMENT)";将媒体项目添加到现有专辑时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆