标签: google-api-nodejs-client

NodeJS Invalid_grant gaxios.js:85:23

在我的 Node.js 应用程序中,我使用带有 oauth2 身份验证的 googleapis 来发送电子邮件。突然,我在启动应用程序时发现了这个错误。

(node:1333) UnhandledPromiseRejectionWarning: Error: invalid_grant
    at Gaxios._request (/Users/danielefarina/Desktop/GIT/server-worldmarker/src/node_modules/gaxios/build/src/gaxios.js:85:23)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async OAuth2Client.refreshTokenNoCache (/Users/danielefarina/Desktop/GIT/server-worldmarker/src/node_modules/google-auth-library/build/src/auth/oauth2client.js:170:21)
    at async OAuth2Client.refreshAccessTokenAsync (/Users/danielefarina/Desktop/GIT/server-worldmarker/src/node_modules/google-auth-library/build/src/auth/oauth2client.js:194:19)
    at async OAuth2Client.getAccessTokenAsync (/Users/danielefarina/Desktop/GIT/server-worldmarker/src/node_modules/google-auth-library/build/src/auth/oauth2client.js:214:23)
(node:1333) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:1333) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled …
Run Code Online (Sandbox Code Playgroud)

node.js google-api-nodejs-client

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

将 google-api-nodejs-client 与 browserify 捆绑在一起不起作用

我正在尝试使用 browserify 使用google-api-nodejs-client构建客户端应用程序。看起来它内部正在尝试使用 fs 模块读取一些 mime 类型信息,但在浏览器中无法执行此操作。

    // Load additional types from node.js community
    mime.load(path.join(__dirname, 'types/node.types'));

    // Default type
    mime.default_type = mime.lookup('bin');
Run Code Online (Sandbox Code Playgroud)

有人用这个API进行客户端开发吗?

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

2
推荐指数
1
解决办法
951
查看次数

使用nodejs google日历API插入事件会返回400:"缺少结束时间"

我正在尝试使用服务帐户通过Google Calendar API插入活动.目标是拥有一个所有用户都可以查看的日历:服务器到服务器的设置.

截至目前,我可以正确调用日历API并列出所述日历上的事件:

var moment = require("moment"),
    googleapis = require("googleapis"),
    googleCal = googleapis.calendar("v3");
    serviceEmail = "********@developer.gserviceaccount.com",
    serviceKeyFile = "./key.pem";

var authClient = new googleapis.auth.JWT(
        serviceEmail,
        serviceKeyFile,
        null,
        ["https://www.googleapis.com/auth/calendar"]
    );

authClient.authorize(function (err, tokens) {
    if (err) {
        console.log(err);
    } else {
        googleCal.events.list({
            auth: authClient,
            calendarId: "********@gmail.com",
            fields: {
                items: ["end","start","summary"]
            }
        }, function (err, CL) {
            if (err) {
                console.log(err);
            } else {
                console.log(CL);
            }
        });
    }
})
Run Code Online (Sandbox Code Playgroud)

这会正确返回一个JSON对象,该对象列出日历上的所有不同对象.但是,当我尝试在googleCal.events.list呼叫的正下方插入事件时:

googleCal.events.insert({
    auth: authClient,
    calendarId: "primary",
    resources: {
        start: { …
Run Code Online (Sandbox Code Playgroud)

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

2
推荐指数
1
解决办法
3760
查看次数

使用node.js直接从服务器使用youtube/google API进行视频上传?

我正在尝试从服务器上传视频而无需用户在客户端进行任何手动身份验证.我尝试使用以下代码片段进行视频上传,但它会在浏览器中对用户进行身份验证,并要求接受该应用.

var ResumableUpload = require('node-youtube-resumable-upload');
var googleauth = require('google-auth-cli');
var google = require('googleapis');

var getTokens = function(callback) {
  googleauth({
      access_type: 'offline',
      scope: 'https://www.googleapis.com/auth/youtube.upload' //can do just 'youtube', but 'youtube.upload' is more restrictive
  },
  {     client_id: CLIENT_ID, //replace with your client_id and _secret
      client_secret: CLIENT_SECRET,
      port: 3000
  },
  function(err, authClient, tokens) {
    console.log(tokens);
    callback(tokens);
  });
};

getTokens(function(result) {
  tokens = result;
  upload();
});



var upload = function() {
      var metadata = {snippet: { title: 'title', description: 'Uploaded with ResumableUpload' },
          status: …
Run Code Online (Sandbox Code Playgroud)

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

2
推荐指数
1
解决办法
5368
查看次数

使用 Node 的 Google API 批量请求

我注意到 Google 最近从他们的 Node 客户端删除了批量请求:

https://github.com/google/google-api-nodejs-client/blob/0db674b7d3a04cf65e223f876cf7b3f427025cd4/MIGRATING.md

如何使用 Node 编写批处理请求?我试图在给定一组邮件 ID 的情况下获取 Gmail 中电子邮件的内容。

以下是 Google 说我应该这样做的方式,但我以前从未提出过此类请求:

https://developers.google.com/gmail/api/guides/batch

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

2
推荐指数
1
解决办法
2858
查看次数

使用Loopback进行文件上传

我创建了一个简单的文件上传应用程序环回.应用程序客户端我使用简单的html和Java Script代码.

我用ajax调用调用loopback api,这是Java脚本代码 -

$('#upload-input').on('change', function () {

    var files = $(this).get(0).files;

    if (files.length > 0) {
        // One or more files selected, process the file upload
        var form = new FormData();

        for (var index = 0; index < files.length; index++) {

            var file = files[index];
            form.append('Uploded Files', file, file.name);
        }

        $.ajax({
            url: 'api/fileupload/upload',
            type: 'POST',
            data: form,
            processData: false,
            contentType: false,
            success: function (data) {
                console.log('upload successful!');
            }
        });
    }

});
Run Code Online (Sandbox Code Playgroud)

但是我们没有在服务器端获取文件.在服务器端,我们创建了一个Loopback api.

可以帮助我们,如何使用loopback api上传文件.

这是我的loopback api代码 - …

jquery loopback node.js google-api-nodejs-client loopbackjs

2
推荐指数
1
解决办法
7008
查看次数

如何使用GCE Node.js客户端从实例模板创建新的GCE VM实例?

Google计算引擎中,我可以使用实例模板从该模板创建新的VM。使用GCE控制台可以正常工作,也可以使用API(URL参数“ sourceInstanceTemplate”)正常工作。

如何使用googleapis / nodejs-compute(Node.js GCE SDK)从实例模板创建新的GCE-VM ?

google-compute-engine google-api-nodejs-client

2
推荐指数
1
解决办法
217
查看次数

如何将 google-auth-library 与 Google Cloud Storage 和 NodeJS 结合使用?

我想在 NodeJS 中使用Google Cloud Storage,但使用google-auth-library进行身份验证 具体来说:我想将其托管在 heroku 上,所以我想将秘密保存在环境变量中,而不是文件中(因为我必须这样做)提交文件以部署到 heroku)。基本上是身份验证库中建议的内容: https ://github.com/googleapis/google-auth-library-nodejs#loading-credentials-from-environment-variables

但我似乎无法将生成的客户端传递给存储构造函数?

node.js google-cloud-storage google-api-nodejs-client google-cloud-platform google-auth-library

2
推荐指数
1
解决办法
2152
查看次数

Google Sheets API——自动获取工作表的最大范围

众所周知,为了从 Google Sheets API 中的行列中获取值,格式如下:

gapi.client.sheets.spreadsheets.values.get({
  spreadsheetId: id,
  range: "myData!A1:E" 
}).then(res => {
  console.log(res.result);
}, err => console.log(err));
Run Code Online (Sandbox Code Playgroud)

请注意,“范围”必须在特定参数内,但如何简单地获取最大范围内的值?是否有像“myData!Min:Max”这样的简写?我知道您可以提出另一个请求来获取最大行和列长度:

sheets.spreadsheets.get({
    spreadsheetId: id,
    ranges: [],
    auth: something
}, (err, resp) => {
    var sheetOne = resp.data.sheets[0];
    console.log(sheetOne.properties.gridProperties); // { rowCount: 1024, columnCount: 7 } (for example)
})
Run Code Online (Sandbox Code Playgroud)

然后一旦我有了,理论上我可以使用数字到字母的切换系统自动生成范围字符串以获取列字母名称或类似的内容,并发出另一个请求以获取最大列,但首先:

  1. 制作一个从数字最大值返回字母格式范围的函数可能很复杂
  2. 即便如此,我只想获取其中包含非空值的范围;如果我有一个 1000 行的电子表格,但只使用前 20 行和列,那么我想自动将范围限制为实际值。

有什么办法可以用 API 来做到这一点吗?

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

2
推荐指数
1
解决办法
8363
查看次数

即使在服务器到服务器身份验证之后也无法使用 Google Play Developer API

我正在尝试从本地服务器调用Purchases.Subscriptions: get,但收到一条错误消息Error: Login Required: 。

我已经创建了一个具有项目所有者角色的服务帐户,如此处所述。然后,我设置GOOGLE_APPLICATION_CREDENTIALS环境变量并使其指向此处提到的下载的 JSON 文件。

最后,我尝试根据网站文档示例运行一些用于服务器到服务器身份验证的示例代码,看看是否可以成功进行身份验证:

import { google } from 'googleapis'

async function main() {
  try {
    const auth = new google.auth.GoogleAuth({
      scopes: ['https://www.googleapis.com/auth/androidpublisher']
    })

    const authClient = await auth.getClient()
    const project = await auth.getProjectId()
    const publisher = google.androidpublisher('v3')

    const result = await publisher.purchases.subscriptions.get({
      packageName: 'com.mywebsite.subdomain',
      subscriptionId: 'com.mywebsite.subscription_name',
      token: '...my purchase token...'
    })

    console.log(result)
  } catch (error) {
    console.error(error)
  }
}

main()
Run Code Online (Sandbox Code Playgroud)

我只是使用了 Billing API …

google-api google-api-client google-api-nodejs-client play-billing-library

2
推荐指数
1
解决办法
2629
查看次数