Working With Public Albums
The CloudikePhotos SDK provides functions for working with public albums.
import CLPhotos from 'web_photos';
let photosApp;
const options = { logLevel: 'error' // 'trace' | 'debug' | 'info' | 'warn' | 'error'};
const config = { authToken: '', // user auth token baseUrl: '', // api base url required userAgent: '' // user agent name required}
try { photosApp = CLPhotos.init(options, config);} catch (e) { // catch photo sdk InternalError}
#
Shared resource operationsThe following code example demonstrates how to get information about share by albumData:IAlbumSchema.
const {albums, publicLinksService} = photosApp; // CLPhotos;albums .getAlbums() .then(({data}) => { const { _embedded: {albums}, } = data; // IAlbumsSchema const [album] = albums; // IAlbumSchema return publicLinksService.getShare(album); }) .then(({data}) => { const share = data; // IMyShareSchema }) .catch((error) => { });
The following code example demonstrates how to create a new share by albumData:IAlbumSchema.
const {albums, publicLinksService} = photosApp; // CLPhotos;albums .getAlbums() .then(({data}) => { const { _embedded: {albums}, } = data; const [album] = albums; // IAlbumSchema const params = {access_type: ShareAccessTypes.ALL}; return publicLinksService.createShare(album, params); }) .then(({data}) => { const share = data; // IMyShareSchema }) .catch((error) => { });
The following code example demonstrates how to update an existing share by albumData:IAlbumSchema.
const {albums, publicLinksService} = photosApp; // CLPhotos;albums .getAlbums() .then(({data}) => { const { _embedded: {albums}, } = data; const [album] = albums; // IAlbumSchema const params = {access_type: ShareAccessTypes.COLLABORATORS}; return publicLinksService.updateShare(album, params); }) .then(({data}) => { const share = data; // IMyShareSchema }) .catch((error) => { });
The following code example demonstrates how to delete an existing share by albumData:IAlbumSchema.
const {albums, publicLinksService} = photosApp; // CLPhotosalbums .getAlbums() .then(({data}) => { const { _embedded: {albums}, } = data; const [album] = albums; // IAlbumSchema return publicLinksService.deleteShare(album); }) .then(({data}) => { const share = data; // IMyShareSchema }) .catch((error) => { });
#
CollaboratorsThe following code example demonstrates how to get a list of collaborators of a share
const {albums, publicLinksService} = photosApp; // CLPhotos;albums .getAlbums() .then(({data}) => { const { _embedded: {albums}, } = data; const [album] = albums; // IAlbumSchema return publicLinksService.getCollaborators(album); }) .then(({data}) => { const share = data; // IMyShareSchema }) .catch((error) => { });
The following code example demonstrates how to add a new Collaborator of a share
const {albums, publicLinksService} = photosApp; // CLPhotos;albums .getAlbums() .then(({data}) => { const { _embedded: {albums}, } = data; const [album] = albums; // IAlbumSchema const params = { phone_or_email: 'example@test.com', permission: SharePermissionType.WRITE, }; return publicLinksService.addCollaborator(album, params); }) .then(({data}) => { const share = data; // IMyShareSchema }) .catch((error) => { });
The following code example demonstrates how to update data of a collaborator
const {albums, publicLinksService} = photosApp; // CLPhotos;albums .getAlbums() .then(({data}) => { const { _embedded: {albums}, } = data; const [album] = albums; // IAlbumSchema return publicLinksService.getCollaborators(album); }) .then(({data}) => { const { _embedded: {collaborators}, } = data; const [collaborator] = collaborators; const params = {permission: SharePermissionType.READ}; return publicLinksService.updateCollaborator(collaborator, params); }) .then(({data}) => { const share = data; // IMyShareSchema }) .catch((error) => { });
The following code example demonstrates how to delete data of a collaborator
const {albums, publicLinksService} = photosApp; // CLPhotos;albums .getAlbums() .then(({data}) => { const { _embedded: {albums}, } = data; const [album] = albums; // IAlbumSchema return publicLinksService.getCollaborators(album); }) .then(({data}) => { const { _embedded: {collaborators}, } = data; const [collaborator] = collaborators; return publicLinksService.deleteCollaborator(collaborator); }) .then(({data}) => { const share = data; // IMyShareSchema }) .catch((error) => { });
#
Not my resourcesThe following code example demonstrates how to get data of shared with owner of the cloud resources
const {publicLinksService} = photosApp; // CLPhotos;publicLinksService.getAllSharedWithMe() .then(({data}) => { // data : ISharedWithMeAlbumsSchema }) .catch((error) => { });
The following code example demonstrates how to get data of a shared with owner of the cloud resource with given shareId
const {publicLinksService} = photosApp; // CLPhotos;const sharedId = '<sharedId>';const accessToken = '<accessToken>';publicLinksService.getSharedWithMe(sharedId, accessToken) .then(({data}) => { // data : INotMyAlbumSchema }) .catch((error) => { });
The following code example demonstrates how to get update data of a shared with owner of the cloud resource with given shareId with the 'write' access type
const {publicLinksService} = photosApp; // CLPhotos;const sharedId = '<sharedId>';const accessToken = '<accessToken>';const params = {description: 'updated shared album'}publicLinksService.updateSharedWithMe(sharedId, params, accessToken) .then(({data}) => { // data : INotMyAlbumSchema }) .catch((error) => { });
The following code example demonstrates how to delete data of a shared with owner of the cloud resource with given shareId with the 'write' access type
const {publicLinksService} = photosApp; // CLPhotos;const sharedId = '<sharedId>';const accessToken = '<accessToken>';publicLinksService.deleteSharedWithMe(sharedId, accessToken) .then(({data}) => { // const data : INotMyAlbumSchema }) .catch((error) => { });
The following code example demonstrates how to get data of a shared with owner of the cloud share of a resource with given shareId
const {publicLinksService} = photosApp; // CLPhotos;const sharedId = '<sharedId>';const accessToken = '<accessToken>';publicLinksService.getSharedWithMeShareById(sharedId, accessToken) .then(({data}) => { // data : INotMyAlbumSchema }) .catch((error) => { });
The following code example demonstrates how to get data of a shared with owner share of the cloud resource with given shareId
const {publicLinksService, user} = photosApp; // CLPhotos;const sharedId = '<sharedId>';const accessToken = '<accessToken>';const userId = '<userId>';user.getUserData().then((account) => { const {user_id: userId} = account; return publicLinksService .getPublicShare(sharedId, userId, accessToken) .then(({data}) => { const share = data; //IPublicShareSchema }) .catch((error) => { });});
The following code example demonstrates how to create a token to get access to a shared owner's share of the cloud resource with given shareId
const {publicLinksService} = photosApp; // CLPhotos;const sharedId = '<sharedId>';const password = '<password>';publicLinksService .createShareToken(sharedId, password) .then(({data}) => { const {token} = data; }) .catch((error) => { });