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)

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

报告相同问题?

悬赏问题

  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元