Created
December 26, 2018 18:17
-
-
Save bfagundez/6c7f8adc5b106f5586e75883318c4e25 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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