Tag: 谷歌的API 的NodeJS客户端

通过云端function访问Gmail API

我正在尝试构build一个响应Gmail邮件发送邮件的电子邮件parsing器。 我目前能够接收和parsingpubsub消息并提取historyId,但我无法validation我的请求到gmail api。 这是我到现在为止: //function defined outside the scope of the main function //used to create auth client function getAuthClient(event, callback) { var GoogleAuth = require('google-auth-library'); var authFactory = new GoogleAuth(); authFactory.getApplicationDefault(function (err, authClient) { if (err) { console.log('Unable to get application default credentials.'); callback(err); return; } // Create the oAuth scopes you need if […]

通过节点客户端调用Google API时出现“套接字挂起”错误

以下代码在此处使用Google的nodejs客户端版本0.7调用Google Analytics报告API。 它在一些执行中返回socket hang up错误,但并不总是如此。 这是否会成为Google服务器端的错误? 有没有简单的方法来debugging? 顺便说一句,我连续打几个电话,不知道是否是由速率限制造成的。 gapi = require "googleapis" authClient = new gapi.auth.JWT( config.ga.clientEmail, config.ga.privateKeyPath, null, [config.ga.scopeUri] ) authPromise = new Promise (resolve, reject) -> authClient.authorize (err, token) -> resolve token return return authPromise.then -> gapi.discover('analytics', 'v3') .withAuthClient(authClient) .execute (err, client) -> …

nodejs googleapis,authClient.request不是一个函数

我在一个函数中创build一个oauth2client,并返回它。 我其实是通过身份证,秘密,redirecturl和凭证。 这些都是我所检查的正确。 var OAuth2 = google.auth.OAuth2; var oauth2Client = new OAuth2(CLIENT_ID, CLIENT_SECRET, REDIRECT_URL); … credentials = { access_token: accessToken, refresh_token: refreshToken }; oauth2Client.setCredentials(credentials); 然后,我在返回oauth2client对象的函数中执行此操作: var plus = google.plus('v1'); console.log(JSON.stringify(oauth_client)); plus.people.get({ userId: 'me' , auth: oauth_client}, function(err, response) { if(err) { console.log(err); } else { console.log(JSON.stringify(response)); return response; } }); 然而,然后我得到一个错误消息说,authClient.request不是一个函数。 TypeError:authClient.request不是createAPIRequest的函数(/node_modules/googleapis/lib/apirequest.js:180:22) 我不知道为什么我得到这个错误。 我也做了console.log(JSON.stringify(oauth_client))来检查请求函数,我没有看到任何。 有人提到,这不能显示完整的原型链,并且请求函数可能实际上在那里。

oauth2Client.getToken缺lessrefresh_token

我有一个小型快递服务器,有两个路线。 然后它将json标记写入一个文件(我知道非常不安全)。 出于某种原因,没有refresh_token 。 在文档中,对于access_type offline的评论获取了已设置的refresh_token ,但仍然不起作用 access_type: 'offline', // 'online' (default) or 'offline' (gets refresh_token) 这里是快递服务器,对不起,如果承诺抛出任何人。 var Promise = require("bluebird") var express = require('express') var app = express() var google = require('googleapis') var OAuth2 = google.auth.OAuth2 var clientSecrets = require("./client_secrets.json") var oauth2Client = new OAuth2(clientSecrets.web.client_id, clientSecrets.web.client_secret, clientSecrets.web.redirect_uris[0]); oauth2Client.getToken = Promise.promisify(oauth2Client.getToken) var fs = Promise.promisifyAll(require("fs")) […]

GoogleloginNodejs中的Android服务器端身份validation

我创build了一个Android应用程序,它向用户请求“服务器authentication码”并将其发送到Nodejs中的后端。 现在,我想用GoogleSign In API来validation这个令牌,并获得“access-token”和“refresh-token”。 我可以在这里看到一个Java / Python示例代码,使用google提供的库: https : //developers.google.com/identity/sign-in/web/server-side-flow 我试图find一个Nodejs类似的库,你可以提供一个片段或一些包,可以帮助我呢?

OAuth2Client应该创build每个请求或caching每个用户?

我正在使用google api客户端的节点版本。 即: google-api-nodejs-client 。 作为这个的一部分,我设置了oauth-flow( 'google webserver'stream程是确切的。) 作为身份validation的一部分,这包括做如下的调用: var oauth2Client = new OAuth2Client(CLIENT_ID, CLIENT_SECRET, REDIRECT_URL); 和 oauth2Client.setCredentials(userSpecificTokens) 显然,第一个调用是特定于应用程序的,而第二个调用是用户特定的。 在这种情况下什么被认为是好的做法? 之一: 每个用户有1个oauth2Client和caching/保存令牌,并在每个请求上使用oauth2Client.setCredentials(userSpecificTokens)注入它们。 这基本上为每个请求创build一个新的oauth2Client 。 每个用户都有一个oauthClient ,包括已经应用的oauth2Client.setCredentials(userSpecificTokens) ,它是在需要时创build的,然后被caching。

Google API NodeJS:calendar.events.watch获取错误push.webhookUrlNotHttps或pushWebhookBadDomain

我已经按照https://developers.google.com/google-apps/calendar/v3/push (我认为)中所需的所有设置,我正在尝试注册我的callbackURL来观看事件,并使用以下代码: calendar.events.watch({ auth:jwtClient, resource: { id: "yourChannelId", type: 'web_hook', address: "https://api.mysite.com/notifications" }, calendarId: "mycalendarId" }, function(error, response) { if (error) { console.log(error); return; } console.log(response); }); 我得到错误message: 'No valid domain for WebHook callback: https://https://api.mysite.com', reason: 'pushWebhookBadDomain' 。 如果我尝试将地址设置为“api.mysite.com/notifications”(因为https看起来是重复的),那么我会收到错误message: 'WebHook callback must be HTTPS: api.mysite.com/notifications', reason: 'push.webhookUrlNotHttps' 任何人都可以帮我吗? 谢谢

Node.js undefined:1

我在执行node.js脚本时遇到以下错误,我尝试通过添加console.log()来追踪错误,但找不到任何解决scheme。 [注:我也search了其他的Stackoverflow解决scheme,但没有帮助] undefined:1 {"ydht":{"status":{"code":200,"message":"OK"},"records":[ ^ SyntaxError: Unexpected end of input at Object.parse (native) at IncomingMessage.<anonymous> (/tmp/subs_20140130/inc/getData.js:36:24) at IncomingMessage.EventEmitter.emit (events.js:95:17) at IncomingMessage.<anonymous> (_stream_readable.js:745:14) at IncomingMessage.EventEmitter.emit (events.js:92:17) at emitReadable_ (_stream_readable.js:407:10) at emitReadable (_stream_readable.js:403:5) at readableAddChunk (_stream_readable.js:165:9) at IncomingMessage.Readable.push (_stream_readable.js:127:10) at HTTPParser.parserOnBody [as onBody] (http.js:142:22) 这是我的代码: var options = { host: '<my host>', port: 3128, path: 'http://<some host>:4080'+searchQuery, […]

使用Google API访问公共日历,无需用户login

我想使用Google的REST API访问公共日历。 Google的日历APIbuild议我需要一个OAuth令牌来访问日历: https://developers.google.com/google-apps/calendar/auth 但是,我正在访问公共日历,并从服务器这样做,所以不能/不应该要求用户进行身份validation。 我正在使用node.js API: googleapis .discover('calendar', 'v3').execute(function(err, client) { client.calendar.calendars.get({ calendarId: '***@group.calendar.google.com' }) .execute(function (err, response) { console.log('response from google', response); }); }); 这返回“您的客户已经发出了一个格式不正确或非法的请求,这就是我们所知道的。 .withApiKey('***')之后调用.withApiKey('***') .calendars.get()返回相同的错误。 有什么build议么?

用于在Node.js中发送邮件的Gmail API

免责声明: 我遵循Google自己的Node.js快速入门指南,并成功连接并使用gmail.users.labels.list()function。 我已经在这里检查了这个问题/答案,就像这个 (不是使用Node.js API),或者这个 (类似于这个 )显然是我有同样的问题,但解决scheme不工作。 我的问题: 当使用Google的Node.js API时,我尝试发送邮件时出错。 错误是: { "code": 403, "errors": [{ "domain": "global", "reason": "insufficientPermissions", "message": "Insufficient Permission" }] } 我的设置: fs.readFile(secretlocation, function processClientSecrets(err, content) { if (err) { console.log('Error loading client secret file: ' + err); return; } authorize(JSON.parse(content), sendMessage); }); function sendMessage(auth) { var raw = makeBody('myrealmail@gmail.com', 'myrealmail@gmail.com', […]