Skip to content

Instantly share code, notes, and snippets.

@nightbear1009
Created May 6, 2019 03:57
Show Gist options
  • Save nightbear1009/4c1367eaa016eb3788ea1b963222b72d to your computer and use it in GitHub Desktop.
Save nightbear1009/4c1367eaa016eb3788ea1b963222b72d to your computer and use it in GitHub Desktop.
const { google } = require('googleapis');
const axios = require('axios')
test()
async function test() {
let accessToken = ''
const jwtClient = new google.auth.JWT(
`aaa@aaaa.iam.gserviceaccount.com`,
`aaaa.p12`,
null,
[`https://www.googleapis.com/auth/cloud-platform`]
)
jwtClient.authorize((err, token) => {
accessToken = token.access_token;
console.log(`access_token: ${accessToken}`)
const axiosInstance = axios.create({
headers: {
'Authorization': `Bearer ${accessToken}`
}
})
axiosInstance.post(
`https://firebase.googleapis.com/v1beta1/projects/xxxx:addFirebase`,
{
timeZone: 'America/Los_Angeles',
regionCode: 'US',
locationId: 'us-central'
}
).then(res => {
console.log(res.data)
}).catch(error => {
console.log(error.response.data)
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment