Saturday, 9 July 2016

nodejs access google drive II

It is very easy to upload images to google Drive because this client api:

https://github.com/google/google-api-nodejs-client

The only two thing they didn't mention in their document are:

1. how to get token.
2. how to put the image into a folder.

1.
Two ways to get the token, i strongly recommend you do the first one first which is manually get the token and think about the second way which is automatically get the token.

You should read my first blog about "node access google drive" to get your client id and security key, then just run this code and you will understand google auth: https://github.com/google/google-api-nodejs-client/blob/master/samples/oauth2.js

Above is the first way, which use access token to get permission for particualr apps, by this way we are getting access token from the url (actrually we access a longer url first which as all apps we want to access then the page will ask a google user to give permission for these apps and after the permission is given, then the url will be redrected to a shorter url which as the access token)

Then the second way uses another token which is REFRESH_TOKEN token to automatically update your access token.  Meaning, you don't have to manually access a url and copy token over again.

If you check "https://developers.google.com/oauthplayground", you will know the refresh_token only work with drive api.


2. put image into a folder on drive:

To get apis and parameters definitions:

https://developers.google.com/drive/v3/web/folder



No comments:

Post a comment