Skip to content

Instantly share code, notes, and snippets.

@bfagundez
Created December 26, 2018 18:17
Show Gist options
  • Save bfagundez/6c7f8adc5b106f5586e75883318c4e25 to your computer and use it in GitHub Desktop.
Save bfagundez/6c7f8adc5b106f5586e75883318c4e25 to your computer and use it in GitHub Desktop.
'use strict'
const { google } = require('googleapis')
const got = require('got')
const key = require('./auth.json')
async function loginWithJWT(){
const scopes = 'https://www.googleapis.com/auth/photoslibrary.readonly';
const jwt = new google.auth.JWT(key.client_email, null, key.private_key, scopes);
console.log('performing login')
try { return jwt.authorize(); }
catch(error) { console.log('something went wrong with auth'); }
}
async function queryPhotos(response){
console.log('querying photos');
try {
const api_call = await got('https://photoslibrary.googleapis.com/v1/mediaItems',
{ json: true, headers: { Authorization: response.token_type+' '+response.access_token } });
return api_call.body;
} catch(error){
console.log('ruh oh');
console.log(error.body);
}
}
async function getMediaLibraryPhotos () {
const auth = await loginWithJWT()
console.log('logged in!',auth);
const query = await queryPhotos(auth)
console.log('queried photos!')
console.log(query)
}
getMediaLibraryPhotos();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment