Google Photos API import all my photos

后端 未结 3 2032
轮回少年
轮回少年 2021-02-07 16:18

I\'ve been reading more or less every StackOverflow question about Google Photos, and still I haven\'t figured out the answer.

I need, for my Rails app, to get the url o

3条回答
  •  余生分开走
    2021-02-07 16:55

    Use the Search call, (https://developers.google.com/photos/library/reference/rest/v1/mediaItems/search) with an empty search string, retrieves all media items.

    I have recently built a tool to backup all my photos (https://github.com/dtylman/gitmoo-goog), following is an example in golang to list the entire library:

    import "google.golang.org/api/photoslibrary/v1"`
    
    func ListAll(svc *photoslibrary.Service) error {
        hasMore := true
        req := &photoslibrary.SearchMediaItemsRequest{PageSize: 50}
        for hasMore {
            items, err := svc.MediaItems.Search(req).Do()
            if err != nil {
                return err
            }
            for _, m := range items.MediaItems {
                fmt.Println(m)
            }
            req.PageToken = items.NextPageToken
            if req.PageToken == "" {
                hasMore = false
            }
        }
        return nil  
    }
    

提交回复
热议问题