NodeJS access API officially supported by Google, which provides background logon authorization and nodejsapi
Install
This library is released through npm. Run the following command to install googleapis and its dependencies:
$ npm install googleapis
Complete list of API support https://developers.google.com/apis-explorer
Use
Example 1: Get the complete address through Google short address
var google = require('googleapis'); var urlshortener = google.urlshortener('v1'); var params = { shortUrl: 'http://goo.gl/xKbRu3' }; // get the long url of a shortened url urlshortener.url.get(params, function (err, response) { console.log('Long url is', response.longUrl); });
Example 2: logon authorization
This example is integrated with oau22. you can obtain the user's access Token and refresh the Token to prevent session expiration.
var google = require('googleapis'); var plus = google.plus('v1'); var oauth2Client = new OAuth2(CLIENT_ID, CLIENT_SECRET, REDIRECT_URL); // Retrieve tokens via token exchange explained above or set them: oauth2Client.setCredentials({ access_token: 'ACCESS TOKEN HERE', refresh_token: 'REFRESH TOKEN HERE' }); plus.people.get({ userId: 'me', auth: oauth2Client }, function(err, response) { // handle err and response });
Complete logon authorization example. Https://github.com/google/google-api-nodejs-client/blob/master/examples/oauth2.js
Example 3: File Upload
var fs = require('fs'); var drive = google.drive({ version: 'v2', auth: oauth2Client }); drive.files.insert({ resource: { title: 'testimage.png', mimeType: 'image/png' }, media: { mimeType: 'image/png', body: fs.createReadStream('awesome.png') // read streams are awesome! } }, callback);
Question?
If you have any questions, you can ask Stackoverflow
If any vulnerability is found, submit the Issue on GitHub.
How does nodejs access external interfaces?
One is premade packages that are referenced by require, such as fs;
Also, access through the network, such as accessing restful APIs through http.
How does js use JS to simulate form submission/login operations on a website of another user? There is another nodejs issue.
1. First you have to use js, then use iframe to load the original webpage, and then call js
2. js is simple. It is written on a webpage and loaded with winform. nodejs is complicated. First, you need to ask the user to install nodejs on windows (I have not tried it) and then call the nodejs environment, nodejs is used as a server in linux and does not work with windows programs.