Giter Site home page Giter Site logo

sudtanj / gas-gphotosapp Goto Github PK

View Code? Open in Web Editor NEW
9.0 1.0 1.0 16 KB

Google Photos REST API library for Google Apps scripts

Home Page: https://photos.google.com/

License: MIT License

JavaScript 100.00%
gas googleappsscript javascript google-apps-script google-appscripts oauth apps-script

gas-gphotosapp's Introduction

GPhotosApp

Google Photos REST API library for Google Apps scripts

Adding the library to your project

GPhotosApp for Google Apps Script is made available as a script library. This is how you add it to your project:

  1. Select "Resources" > "Libraries..." in the Google Apps Script editor.
  2. Enter the project key (M7RP1Hdti0BfRh6z0gqmWISI0h1vB8tqc) in the "Find a Library" field, and choose "Select". (If you have copied the library, enter instead the project key of your copy.)
  3. Select the highest version number, and choose GPhotosApp as the identifier. (Do not turn on Development Mode unless you know what you are doing. The development version may not work.)
  4. Press Save. You can now use the GPhotosApp library in your code.

Redirect URI

Before you can start authenticating against an OAuth2 provider, you usually need to register your application with that OAuth2 provider and obtain a client ID and secret. Often a provider's registration screen requires you to enter a "Redirect URI", which is the URL that the user's browser will be redirected to after they've authorized access to their account at that provider.

For this library (and the Apps Script functionality in general) the URL will always be in the following format:

https://script.google.com/macros/d/{SCRIPT ID}/usercallback

Where {SCRIPT ID} is the ID of the script that is using this library. You can find your script's ID in the Apps Script code editor by clicking on the menu item "File > Project properties".

Usage

To use the library, you need the following code to be included in your project.

clientId="OAUTH2_CLIENT_ID"
clientSecret="OAUTH2_CLIENT_SECRET"
GPhotosApp.init(clientId, clientSecret);
function run(){
//check if user already authenticated with OAuth2 
  if(!GPhotosApp.isAuthenticated()){
  //display the authentication link if not authenticated
  //link will be available at log and need to be open
  //user just need to follow the instruction and just rerun this code after it's done authenticate 
    Logger.log(GPhotosApp.doAuthentication());
    return 1;
  }
  // your program
}

function authCallback(request){
  return GPhotosApp.authCallback(request);
}

Uploading image

GPhotosApp.uploadPhoto(mediaBlob,mediaName); // for images or video () (image size limit, refer to https://developers.google.com/photos/library/guides/api-limits-quotas)

Uploading image to album

GPhotosApp.uploadPhotoToAlbum(mediaBlob,mediaName,googlePhotoAlbumId); // for images or video () (image size limit, refer to https://developers.google.com/photos/library/guides/api-limits-quotas)

Logout (remove authenticated user)

GPhotosApp.logout();

Depedencies

  1. apps-script-oauth2 - https://github.com/gsuitedevs/apps-script-oauth2

License

GPhotosApp for Google Apps Script is released under the MIT license.

gas-gphotosapp's People

Contributors

sudtanj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

emptyops

gas-gphotosapp's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.