小编kev*_*n05的帖子

通过云功能访问Gmail API

我正在尝试构建一个响应gmail pubsub消息的电子邮件解析器.我目前能够接收和解析pubsub消息并解压缩historyId,但是我无法验证我对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 (authClient.createScopedRequired && authClient.createScopedRequired()) {
    console.log('creating scoped client');
      authClient = authClient.createScoped([
          'https://mail.google.com/'
      ]);
    }
   callback(null, authClient);
  });
}

exports.gmailParser = function gmailParser (event, callback) {
 var path …
Run Code Online (Sandbox Code Playgroud)

node.js google-api-nodejs-client gmail-api google-oauth2 google-cloud-functions

8
推荐指数
1
解决办法
1924
查看次数