富贵资源网 Design By www.hznty.com

安装

此库通过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);

问题解答"external nofollow" target="_blank" href="http://stackoverflow.com/questions/tagged/google-api-nodejs-client">Stackoverflow 提问

如果发现漏洞可到GitHub上提交 Issue

富贵资源网 Design By www.hznty.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
富贵资源网 Design By www.hznty.com