标签: google-api-nodejs-client

镜像API和Node.JS

我有一个node.js程序,我正在尝试使用googleapis模块(https://github.com/google/google-api-nodejs-client)版本0.2.5-alpha.

我可以毫无问题地使用原始HTTP进行调用,因此我知道我在API中列出了白名单,我正在进行身份验证和授权,并且正在请求正确的范围和所有内容.如果我使用相同的access_token在时间轴中插入,我在回调中收到错误.我也发现了plus API,使用这个API的调用工作正常.

用于发现API的代码片段,看起来没有问题:

var client;
googleapis
  .discover( 'plus', 'v1' )
  .discover( 'mirror', 'v1' )
  .execute( function(err,data){
    console.log( err );
    client = data;
  });
Run Code Online (Sandbox Code Playgroud)

执行调用的代码片段:

  client.mirror.timeline.insert({
    text: "test 1 "
  } ).withAuthClient(user.auth).execute(function(err,result,res){
      console.log( '++ start ++' );
      console.log( '+err   ', err );
      console.log( '+result', result );
      //console.log( '+res   ', res );
      console.log( '++ end   ++' );
  });

回调期间记录的内容:

++ start ++
+err    { code: 400,
  message: 'Required',
  data: [ { domain: 'global', reason: 'required', message: 'Required' } ] …

google-api-client google-mirror-api google-api-nodejs-client

4
推荐指数
1
解决办法
921
查看次数

NodeJS Google Api 客户端:我怎么知道访问令牌已过期?

我正在研究 Nodejs Google Api 客户端 Oauth 进程。我遵循 oauth 的代码示例,https://github.com/google/google-api-nodejs-client/blob/master/examples/oauth2.js

我有一个问题。如何检查访问令牌是否已过期以及如何使用刷新令牌再次获取另一个访问令牌?

更具体地说,假设可以访问 google+ 用户个人资料,因此我使用访问令牌来获取用户个人资料:

getAccessToken(oauth2Client, function() {
    // retrieve user profile
    getUserProfile(client, oauth2Client, 'me', function(err, profile) {
      if (err) {
        console.log('An error occured', err);
        return;
      }
      console.log(profile.displayName, ':', profile.tagline);
    });
  });
Run Code Online (Sandbox Code Playgroud)

此外,在应用程序的客户端(backbonejs),如果我尝试使用 google api JS 客户端访问 google drive api(不是 google plus),我不确定是否可以使用我从中获得的访问令牌应用程序的服务器端(nodejs),或者我必须使用 google api JS 客户端执行另一个 OAuth。

google-api node.js google-api-nodejs-client

4
推荐指数
1
解决办法
3301
查看次数

使用Google API仅使用访问令牌发送电子邮件

我想通过Google API发送电子邮件,而不需要不必要的OAUTH2参数.我只有该用户的access_token和refresh_token.

如何使用Request npm插件通过NodeJS中的基本POST请求通过Gmail API发送电子邮件?

google-api node.js google-api-nodejs-client gmail-api

4
推荐指数
1
解决办法
3499
查看次数

如何从其他节点js文件中调用该函数

这些代码存储在单独的文件中,我试图将get方法从此文件调用到另一个nodejs,但我只将[Function]作为输出.

任何人都可以告诉我如何从这个文件调用get方法到另一个节点js文件

'use strict';
var createAPIRequest = require('../../lib/apirequest');
function Fitness(options) {
  var self = this;
  this._options = options || {};
  this.users = {
    dataSources: {
      get: function(params, callback) {
        var parameters = {
          options: {
            url: 'https://www.googleapis.com/fitness/v1/users/{userId}/dataSources/{dataSourceId}',
            method: 'GET'
          },
          params: params,
          requiredParams: ['userId', 'dataSourceId'],
          pathParams: ['dataSourceId', 'userId'],
          context: self
        };
        return createAPIRequest(parameters, callback);
      }     }   }; }
Run Code Online (Sandbox Code Playgroud)

node.js google-api-nodejs-client google-fit

4
推荐指数
1
解决办法
3万
查看次数

Google API,drive.files.list和仅返回子文件

我在NodeJS中使用' googleapis '库,我正在尝试返回当前指定文件夹中的文件和文件夹列表,但我发现drive.files.list返回用户已被授予读取权限的所有文件.

我的目标是能够下载给定文件夹下的文件夹结构,然后NodeJS应用程序可以以有意义的方式使用它.

我使用的代码如下:

const fs = require('fs');
const google = require('googleapis');
const OAuth2 = google.auth.OAuth2;
const key = require('./key.json');

const jwtClient = new google.auth.JWT(
  key.client_email,
  null,
  key.private_key,
  ['https://www.googleapis.com/auth/drive'],
  null
);

const drive = google.drive({
  version: 'v3',
  auth: jwtClient
});

jwtClient.authorize(function (err, tokens) {
  if (err) {
    console.log(err);
    return;
  }

  // Make an authorized request to list Drive files.
  drive.files.list({
     includeRemoved: false,
     spaces: 'drive',
     fileId: 'the-file-id-of-the-folder'
  }, function (err, resp) {
    if (!err) {
        var …
Run Code Online (Sandbox Code Playgroud)

node.js google-drive-api google-api-nodejs-client

4
推荐指数
1
解决办法
3333
查看次数

Google 身份验证令牌返回不包含刷新令牌

我写了一个关于 google api 使用的例子。谷歌 NodeJS 客户端库。我已遵循指令集access_type : 'offline',但是对象返回不包含refresh_token.

我的代码:

var http = require('http');
var express = require('express');
var Session = require('express-session');
var google = require('googleapis');
var plus = google.plus('v1');
var OAuth2 = google.auth.OAuth2;
const ClientId = "251872680446-rvkcvm5mjn1ps32iabf4i2611hcg086e.apps.googleusercontent.com";
const ClientSecret = "F1qG9fFS-QwcrEfZbT8VmUnx";
const RedirectionUrl = "http://localhost:8081/oauthCallback";

var app = express();
app.use(Session({
    secret: 'raysources-secret-19890913007',
    resave: true,
    saveUninitialized: true
}));

function getOAuthClient () {
    return new OAuth2(ClientId ,  ClientSecret, RedirectionUrl);
}

function getAuthUrl () {
    var oauth2Client …
Run Code Online (Sandbox Code Playgroud)

javascript google-api node.js google-oauth google-api-nodejs-client

4
推荐指数
1
解决办法
1558
查看次数

Google DRIVE API V3 - 使用nodejs获取根文件夹ID

我需要获取根文件夹ID和过滤器文件夹,其中根文件夹作为其父文件夹.使用Nodejs和google drive API v3.这是我的代码以及如何更改此代码以获取root folderId?

const service = google.drive('v3');
			service.files.list({
			auth: client2,
			fields: 'nextPageToken, files(id, name, webContentLink, webViewLink, mimeType, parents)'
		  	}, (err, res) => {
			if (err) {
			  console.error('The API returned an error.');
			  throw err;
			}
			const files = res.data.files;
			if (files.length === 0) {
			  console.log('No files found.');
			} else {
				
			  console.log('Files Found!');
			  for (const file of files) {
			  		console.log(`${file.name} (${file.id})`);

			  }
Run Code Online (Sandbox Code Playgroud)

javascript node.js google-drive-api google-api-nodejs-client google-drive-shared-drive

4
推荐指数
1
解决办法
1584
查看次数

将 API 密钥与节点 js 谷歌库一起使用

我正在尝试使用支持 api 密钥类型凭据的 google youtube 数据 api。

https://developers.google.com/youtube/registering_an_application

我正在尝试使用节点 js 的 google auth 库与 apis 进行通信

https://github.com/googleapis/google-auth-library-nodejs

有一个带有 oAuth 凭据和服务帐户凭据的 API 示例。

我知道 api 密钥应该被客户端应用程序使用,比如基于浏览器的 javascripts。所以我看到了基于浏览器的谷歌 api 的例子。

但是是否有任何示例可以将 api 密钥与 google node js 客户端库一起使用?

此致,

索拉夫

google-api google-api-nodejs-client youtube-data-api

4
推荐指数
1
解决办法
1840
查看次数

Gmail API 的访问令牌过期和创建

我一直在使用 google API 从我的 node.js 项目中的服务器发送电子邮件。我已经设置了凭据并创建了刷新令牌和访问令牌,并且已经使用相同的内容超过 6 个月了,就像这样。

oAuth2Client = new google.auth.OAuth2(client_id, client_secret, redirect_uris);
oAuth2Client.setCredentials({ refresh_token, access_token, scope, expiry_date });
gmail = google.gmail({ version: 'v1', oAuth2Client });
gmail.users.messages.send({ /* email details */ });
Run Code Online (Sandbox Code Playgroud)

expiry_date 发送的是我第一次创建令牌时收到的日期,因此该日期是过去的日期(超过 6 个月)。

我记得读过访问令牌会在一段时间后过期,但我不确定我的 access_token 何时过期或我将如何创建一个新的。我的电子邮件仍在发送,所以我有点困惑为什么它还没有停止工作。

所以我的问题本质上是

  1. 我如何知道我的 access_token 何时到期。
  2. 一旦过期,我如何创建一个新的。当我第一次设置所有这些时,我记得是在操场上进行的,但如果可以的话,我更愿意在服务器代码本身中设置 access_token 创建过程。

javascript google-api node.js google-oauth google-api-nodejs-client

4
推荐指数
1
解决办法
5383
查看次数

如何使用 Nodejs 在没有 OAuth 的情况下使用 Google Drive API?

在搜索 stackoverflow、博客、YouTube、Google Drive API 文档等后,大多数示例都展示了如何通过 OAuth 使用 Drive API。

\n

我想构建一个 Nodejs 应用程序,只有当新用户在我的应用程序中创建帐户时,Nodejs 服务器才会在 Google Drive 上创建电子表格。然后该电子表格将可供应用程序管理员使用。

\n

这是一个服务器端进程,因此不需要 OAuth 同意屏幕等

\n

有没有办法仅通过 API 密钥和 REST URL\xe2\x80\x99s 使用 Drive API

\n

下面的 Google 文档链接提供了仅使用 REST URL\xe2\x80\x99s 与 Drive API 交互的示例。

\n

https://developers.google.com/drive/api/v3/reference/files/create

\n

Google 文档对于如何使用上面链接中的 API 密钥和 REST URL\xe2\x80\x99s 的 Drive API 含糊其辞,因为示例使用 REST URL\xe2\x80\x99s 来创建文件等

\n

google-api node.js google-drive-api google-oauth google-api-nodejs-client

4
推荐指数
1
解决办法
1767
查看次数