[gapi.client.photoslibrary] Add Google Photos Library API (#41311)

This commit is contained in:
Nick Amoscato
2020-01-03 18:38:57 -05:00
committed by Ryan Cavanaugh
parent ec7421505e
commit d8a010a0a6
5 changed files with 2017 additions and 0 deletions

View File

@@ -0,0 +1,319 @@
/* This is stub file for gapi.client.photoslibrary definition tests */
/* IMPORTANT.
* This file was automatically generated by https://github.com/Maxim-Mazurok/google-api-typings-generator. Please do not edit it manually.
* In case of any problems please post issue to https://github.com/Maxim-Mazurok/google-api-typings-generator
**/
gapi.load('client', () => {
/** now we can use gapi.client */
gapi.client.load('photoslibrary', 'v1', () => {
/** now we can use gapi.client.photoslibrary */
/** don't forget to authenticate your client before sending any request to resources: */
/** declare client_id registered in Google Developers Console */
const client_id = '<<PUT YOUR CLIENT ID HERE>>';
const scope = [
/** View and manage your Google Photos library */
'https://www.googleapis.com/auth/photoslibrary',
/** Add to your Google Photos library */
'https://www.googleapis.com/auth/photoslibrary.appendonly',
/** View your Google Photos library */
'https://www.googleapis.com/auth/photoslibrary.readonly',
/** Manage photos added by this app */
'https://www.googleapis.com/auth/photoslibrary.readonly.appcreateddata',
/** Manage and add to shared albums on your behalf */
'https://www.googleapis.com/auth/photoslibrary.sharing',
];
const immediate = false;
gapi.auth.authorize({ client_id, scope, immediate }, authResult => {
if (authResult && !authResult.error) {
/** handle successful authorization */
run();
} else {
/** handle authorization error */
}
});
});
async function run() {
/** Adds an enrichment at a specified position in a defined album. */
await gapi.client.photoslibrary.albums.addEnrichment({
albumId: "Test string",
}, {
albumPosition: {
position: "Test string",
relativeEnrichmentItemId: "Test string",
relativeMediaItemId: "Test string",
},
newEnrichmentItem: {
locationEnrichment: {
location: {
latlng: {
latitude: 42,
longitude: 42,
},
locationName: "Test string",
},
},
mapEnrichment: {
destination: {
latlng: {
latitude: 42,
longitude: 42,
},
locationName: "Test string",
},
origin: {
latlng: {
latitude: 42,
longitude: 42,
},
locationName: "Test string",
},
},
textEnrichment: {
text: "Test string",
},
},
});
/**
* Adds one or more media items in a user's Google Photos library to
* an album. The media items and albums must have been created by the
* developer via the API.
*
* Media items are added to the end of the album. If multiple media items are
* given, they are added in the order specified in this call.
*
* Each album can contain up to 20,000 media items.
*
* Only media items that are in the user's library can be added to an
* album. For albums that are shared, the album must either be owned by the
* user or the user must have joined the album as a collaborator.
*
* Partial success is not supported. The entire request will fail if an
* invalid media item or album is specified.
*/
await gapi.client.photoslibrary.albums.batchAddMediaItems({
albumId: "Test string",
}, {
mediaItemIds: [
"Test string" ],
});
/**
* Removes one or more media items from a specified album. The media items and
* the album must have been created by the developer via the API.
*
* For albums that are shared, this action is only supported for media items
* that were added to the album by this user, or for all media items if the
* album was created by this user.
*
* Partial success is not supported. The entire request will fail and no
* action will be performed on the album if an invalid media item or album is
* specified.
*/
await gapi.client.photoslibrary.albums.batchRemoveMediaItems({
albumId: "Test string",
}, {
mediaItemIds: [
"Test string" ],
});
/** Creates an album in a user's Google Photos library. */
await gapi.client.photoslibrary.albums.create({
}, {
album: {
coverPhotoBaseUrl: "Test string",
coverPhotoMediaItemId: "Test string",
id: "Test string",
isWriteable: true,
mediaItemsCount: "Test string",
productUrl: "Test string",
shareInfo: {
isJoined: true,
isOwned: true,
shareToken: "Test string",
shareableUrl: "Test string",
sharedAlbumOptions: {
isCollaborative: true,
isCommentable: true,
},
},
title: "Test string",
},
});
/**
* Returns the album based on the specified `albumId`.
* The `albumId` must be the ID of an album owned by the user or a shared
* album that the user has joined.
*/
await gapi.client.photoslibrary.albums.get({
albumId: "Test string",
});
/**
* Lists all albums shown to a user in the Albums tab of the Google
* Photos app.
*/
await gapi.client.photoslibrary.albums.list({
excludeNonAppCreatedData: true,
pageSize: 42,
pageToken: "Test string",
});
/**
* Marks an album as shared and accessible to other users. This action can
* only be performed on albums which were created by the developer via the
* API.
*/
await gapi.client.photoslibrary.albums.share({
albumId: "Test string",
}, {
sharedAlbumOptions: {
isCollaborative: true,
isCommentable: true,
},
});
/**
* Marks a previously shared album as private. This means that the album is
* no longer shared and all the non-owners will lose access to the album. All
* non-owner content will be removed from the album. If a non-owner has
* previously added the album to their library, they will retain all photos in
* their library. This action can only be performed on albums which were
* created by the developer via the API.
*/
await gapi.client.photoslibrary.albums.unshare({
albumId: "Test string",
}, {
});
/**
* Creates one or more media items in a user's Google Photos library.
*
* This is the second step for creating a media item. For details regarding
* Step 1, uploading the raw bytes to a Google Server, see
* <a href="/photos/library/guides/upload-media">Uploading media</a>.
*
* This call adds the media item to the library. If an album `id` is
* specified, the call adds the media item to the album too. Each album can
* contain up to 20,000 media items. By default, the media item will be added
* to the end of the library or album.
*
* If an album `id` and position are both defined, the media item is
* added to the album at the specified position.
*
* If the call contains multiple media items, they're added at the specified
* position.
* If you are creating a media item in a shared album where you are not the
* owner, you are not allowed to position the media item. Doing so will result
* in a `BAD REQUEST` error.
*/
await gapi.client.photoslibrary.mediaItems.batchCreate({
}, {
albumId: "Test string",
albumPosition: {
position: "Test string",
relativeEnrichmentItemId: "Test string",
relativeMediaItemId: "Test string",
},
newMediaItems: [
{
description: "Test string",
simpleMediaItem: {
fileName: "Test string",
uploadToken: "Test string",
},
} ],
});
/**
* Returns the list of media items for the specified media item identifiers.
* Items are returned in the same order as the supplied identifiers.
*/
await gapi.client.photoslibrary.mediaItems.batchGet({
mediaItemIds: "Test string",
});
/** Returns the media item for the specified media item identifier. */
await gapi.client.photoslibrary.mediaItems.get({
mediaItemId: "Test string",
});
/** List all media items from a user's Google Photos library. */
await gapi.client.photoslibrary.mediaItems.list({
pageSize: 42,
pageToken: "Test string",
});
/**
* Searches for media items in a user's Google Photos library.
* If no filters are set, then all media items in the user's library are
* returned.
* If an album is set, all media items in the specified album are returned.
* If filters are specified, media items that match the filters from the
* user's library are listed. If you set both the album and the filters, the
* request results in an error.
*/
await gapi.client.photoslibrary.mediaItems.search({
}, {
albumId: "Test string",
filters: {
contentFilter: {
excludedContentCategories: [
"Test string" ],
includedContentCategories: [
"Test string" ],
},
dateFilter: {
dates: [
{
day: 42,
month: 42,
year: 42,
} ],
ranges: [
{
endDate: {
day: 42,
month: 42,
year: 42,
},
startDate: {
day: 42,
month: 42,
year: 42,
},
} ],
},
excludeNonAppCreatedData: true,
featureFilter: {
includedFeatures: [
"Test string" ],
},
includeArchivedMedia: true,
mediaTypeFilter: {
mediaTypes: [
"Test string" ],
},
},
pageSize: 42,
pageToken: "Test string",
});
/** Returns the album based on the specified `shareToken`. */
await gapi.client.photoslibrary.sharedAlbums.get({
shareToken: "Test string",
});
/** Joins a shared album on behalf of the Google Photos user. */
await gapi.client.photoslibrary.sharedAlbums.join({
}, {
shareToken: "Test string",
});
/**
* Leaves a previously-joined shared album on behalf of the Google Photos
* user. The user must not own this album.
*/
await gapi.client.photoslibrary.sharedAlbums.leave({
}, {
shareToken: "Test string",
});
/**
* Lists all shared albums available in the Sharing tab of the
* user's Google Photos app.
*/
await gapi.client.photoslibrary.sharedAlbums.list({
excludeNonAppCreatedData: true,
pageSize: 42,
pageToken: "Test string",
});
}
});

1454
types/gapi.client.photoslibrary/index.d.ts vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,212 @@
# TypeScript typings for Photos Library API v1
Manage photos, videos, and albums in Google Photos
For detailed description please check [documentation](https://developers.google.com/photos/).
## Installing
Install typings for Photos Library API:
```
npm install @types/gapi.client.photoslibrary@v1 --save-dev
```
## Usage
You need to initialize Google API client in your code:
```typescript
gapi.load("client", () => {
// now we can use gapi.client
// ...
});
```
Then load api client wrapper:
```typescript
gapi.client.load('photoslibrary', 'v1', () => {
// now we can use gapi.client.photoslibrary
// ...
});
```
Don't forget to authenticate your client before sending any request to resources:
```typescript
// declare client_id registered in Google Developers Console
var client_id = '',
scope = [
// View and manage your Google Photos library
'https://www.googleapis.com/auth/photoslibrary',
// Add to your Google Photos library
'https://www.googleapis.com/auth/photoslibrary.appendonly',
// View your Google Photos library
'https://www.googleapis.com/auth/photoslibrary.readonly',
// Manage photos added by this app
'https://www.googleapis.com/auth/photoslibrary.readonly.appcreateddata',
// Manage and add to shared albums on your behalf
'https://www.googleapis.com/auth/photoslibrary.sharing',
],
immediate = true;
// ...
gapi.auth.authorize({ client_id: client_id, scope: scope, immediate: immediate }, authResult => {
if (authResult && !authResult.error) {
/* handle successful authorization */
} else {
/* handle authorization error */
}
});
```
After that you can use Photos Library API resources:
```typescript
/*
Adds an enrichment at a specified position in a defined album.
*/
await gapi.client.albums.addEnrichment({ albumId: "albumId", });
/*
Adds one or more media items in a user's Google Photos library to
an album. The media items and albums must have been created by the
developer via the API.
Media items are added to the end of the album. If multiple media items are
given, they are added in the order specified in this call.
Each album can contain up to 20,000 media items.
Only media items that are in the user's library can be added to an
album. For albums that are shared, the album must either be owned by the
user or the user must have joined the album as a collaborator.
Partial success is not supported. The entire request will fail if an
invalid media item or album is specified.
*/
await gapi.client.albums.batchAddMediaItems({ albumId: "albumId", });
/*
Removes one or more media items from a specified album. The media items and
the album must have been created by the developer via the API.
For albums that are shared, this action is only supported for media items
that were added to the album by this user, or for all media items if the
album was created by this user.
Partial success is not supported. The entire request will fail and no
action will be performed on the album if an invalid media item or album is
specified.
*/
await gapi.client.albums.batchRemoveMediaItems({ albumId: "albumId", });
/*
Creates an album in a user's Google Photos library.
*/
await gapi.client.albums.create({ });
/*
Returns the album based on the specified `albumId`.
The `albumId` must be the ID of an album owned by the user or a shared
album that the user has joined.
*/
await gapi.client.albums.get({ albumId: "albumId", });
/*
Lists all albums shown to a user in the Albums tab of the Google
Photos app.
*/
await gapi.client.albums.list({ });
/*
Marks an album as shared and accessible to other users. This action can
only be performed on albums which were created by the developer via the
API.
*/
await gapi.client.albums.share({ albumId: "albumId", });
/*
Marks a previously shared album as private. This means that the album is
no longer shared and all the non-owners will lose access to the album. All
non-owner content will be removed from the album. If a non-owner has
previously added the album to their library, they will retain all photos in
their library. This action can only be performed on albums which were
created by the developer via the API.
*/
await gapi.client.albums.unshare({ albumId: "albumId", });
/*
Creates one or more media items in a user's Google Photos library.
This is the second step for creating a media item. For details regarding
Step 1, uploading the raw bytes to a Google Server, see
<a href="/photos/library/guides/upload-media">Uploading media</a>.
This call adds the media item to the library. If an album `id` is
specified, the call adds the media item to the album too. Each album can
contain up to 20,000 media items. By default, the media item will be added
to the end of the library or album.
If an album `id` and position are both defined, the media item is
added to the album at the specified position.
If the call contains multiple media items, they're added at the specified
position.
If you are creating a media item in a shared album where you are not the
owner, you are not allowed to position the media item. Doing so will result
in a `BAD REQUEST` error.
*/
await gapi.client.mediaItems.batchCreate({ });
/*
Returns the list of media items for the specified media item identifiers.
Items are returned in the same order as the supplied identifiers.
*/
await gapi.client.mediaItems.batchGet({ });
/*
Returns the media item for the specified media item identifier.
*/
await gapi.client.mediaItems.get({ mediaItemId: "mediaItemId", });
/*
List all media items from a user's Google Photos library.
*/
await gapi.client.mediaItems.list({ });
/*
Searches for media items in a user's Google Photos library.
If no filters are set, then all media items in the user's library are
returned.
If an album is set, all media items in the specified album are returned.
If filters are specified, media items that match the filters from the
user's library are listed. If you set both the album and the filters, the
request results in an error.
*/
await gapi.client.mediaItems.search({ });
/*
Returns the album based on the specified `shareToken`.
*/
await gapi.client.sharedAlbums.get({ shareToken: "shareToken", });
/*
Joins a shared album on behalf of the Google Photos user.
*/
await gapi.client.sharedAlbums.join({ });
/*
Leaves a previously-joined shared album on behalf of the Google Photos
user. The user must not own this album.
*/
await gapi.client.sharedAlbums.leave({ });
/*
Lists all shared albums available in the Sharing tab of the
user's Google Photos app.
*/
await gapi.client.sharedAlbums.list({ });
```

View File

@@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"strictFunctionTypes": true
},
"files": [
"index.d.ts",
"gapi.client.photoslibrary-tests.ts"
]
}

View File

@@ -0,0 +1,8 @@
{
"extends": "dtslint/dt.json",
"rules": {
"interface-name": [false],
"ban-types": [false],
"await-promise": [true, "Request"]
}
}