douxuexiao1748 2019-05-30 08:17
浏览 108
已采纳

Google照片返回“错误400:请求包含无效的媒体项目ID。 (INVALID_ARGUMENT)”将媒体项目添加到现有相册中

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
}

The server returns the following error:

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

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).

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

Thank you.

  • 写回答

1条回答 默认 最新

  • douqi2571 2019-07-05 06:27
    关注

    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.

    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)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器