A fork of a Meteor library to interact with Google's API (original here : https://atmospherejs.com/percolate/google-api) Combined extra commits from https://github.com/danopia/meteor-google-api/ to use different hosts for google apis e.g. spreadsheets. Pass in a 'host' key value pair in 'options' object while creating request.
Works with accounts-google to automatically handle refresh/access token changes and give you a simple API to make calls.
meteor add tushark:google-api
To call the library, use the get()
and post()
functions:
GoogleApi.get('/your/api/path', options[, callback]);
If callback
is provided (client or server), the call will be made asynchronously.
Available methods: GoogleApi.get
, GoogleApi.post
, GoogleApi.patch
, GoogleApi.put
, GoogleApi.delete
GoogleApi
is a Google OAuth authentication wrapper around HTTP
, so it takes the same arguments. For example, to pass a JSON body in GoogleApi.post
, use:
GoogleApi.post('/your/api/path', { data: jsonBody });
On the client, if you do not provide a callback, the library will return a Q promise. On the server, it will run synchronously.
If the user's access token has expired, it will transparently call the exchangeRefreshToken
method to get a new refresh token. To call this method manually (e.g. from other Google API packages), use Meteor.call('exchangeRefreshToken'[, userId])
. You should first check that that the user's token has actually expired, though, since this method won't.
If you are running client side or in a method call, the package will automatically use the OAuth access token of the current user, and use the refresh token to refresh it if it's out of date (saving to the database also).
If you are running from a context without a Meteor.user()
, you can pass {user: X}
in the options
argument to achieve this behaviour.
Are welcome.
MIT license, (c) Percolate Studio, maintained by Tom Coleman (@tmeasday).