google-api-utility module
google-api-utility是筆者改寫googleapis中access token使用方式的Oauth認證套件,該套件使用Service Account以JWT方式作為基本操作。
Github repository
https://github.com/peihsinsu/google-api-utility
Installation
npm install google-api-utility
申請Oauth2 (同googleapis)
需要到Google Cloud Console中申請,進入:http://cloud.google.com/console 後,點選進入您您的專案後,進入 APIs & auth > Credentials 申請。
Service Account Auth Sample Usage
var auth = require('google-api-utility')
, request = auth.request
, util = require('util')
, project = 'your-project-id';
auth.init({
scope: 'https://www.googleapis.com/auth/bigquery https://www.googleapis.com/auth/cloud-platform',
client_secret: '/path-to-client_secret.json',
key_pem: '/path-to-key.pem',
timeout: 1200
});
var bqurl = 'https://www.googleapis.com/bigquery/v2/projects/%s/datasets';
request({
url: util.format(bqurl, project),
method: 'GET'
}, function(err, req, doc){
if(err) console.log(err);
console.log(doc);
});