tanaikech / GPhotoApp

This is a GAS library for retrieving and creating the albums and media items using Google Photo API using Google Apps Script (GAS).
MIT License
54 stars 7 forks source link

Add Function Search Items By AlbumId #2

Closed vuduongtp closed 2 years ago

vuduongtp commented 3 years ago

If you want to get all media items of the album. You can use this function. Thank you for helpful library. SearchMediaItemList(id_album) { var mediaItems, pageToken, params, res, url; url = "https://photoslibrary.googleapis.com/v1/mediaItems:search"; var payload = { 'albumId': id_album }; params = { method: 'post', muteHttpExceptions: true, headers: { Authorization:Bearer ${this.accessToken} }, payload : payload }; mediaItems = []; pageToken = ""; params.url = url; while (true) { payload.pageToken = pageToken ? pageToken : ''; params.payload = payload; res = UrlFetchApp.fetchAll([params])[0]; r = JSON.parse(res.getContentText()); if (res.getResponseCode() !== 200) { throw new Error(res.getContentText()); } Array.prototype.push.apply(mediaItems, r.mediaItems); pageToken = r.nextPageToken; if (!pageToken) { break; } } return mediaItems; }

Full code at: https://pastebin.com/qg1fQsfW

vuduongtp commented 2 years ago

It is added in commit of @kwikwag