Google官方支援的NodeJS訪問API,提供後台登入授權,nodejsapi

來源:互聯網
上載者:User

Google官方支援的NodeJS訪問API,提供後台登入授權,nodejsapi

安裝

此庫通過npm發布。通過以下命令安裝googleapis及其依賴

$ npm install googleapis

完整的API支援列表 https://developers.google.com/apis-explorer

使用

例1: 通過Google短地址擷取完整地址

 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); });

例2: 登入授權

此樣本整合OAuth2認證,可以讓你擷取到使用者的訪問Token並重新整理此Token防止會話到期。

  

 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 });

完整的登入授權樣本。 https://github.com/google/google-api-nodejs-client/blob/master/examples/oauth2.js

例3: 檔案上傳

 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);

問題解答?

如有任何問題可到 Stackoverflow 提問

如果發現漏洞可到GitHub上提交 Issue


nodejs怎訪問外部介面

一種是預製的包,通過require來引用,比如fs;
還有,使用網路來訪問,比如使用http訪問restful API。
 
js怎在一個別人的網站上利用JS類比提交表單/登入操作什的?還有一個nodejs問題

1、首先你得會js,然後使用iframe裝載原網頁,再調用其中js
2、js簡單,寫在網頁裡,用winform載入網頁,nodejs比較複雜,首先你要讓使用者在windows上安裝nodejs(我沒試過),然後再調用nodejs環境,nodejs是linux下用來做伺服器的,和windows程式不搭邊。
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.