簡體   English   中英

使用訪問令牌調用Google API

[英]Call google API with access token

從客戶端登錄並在服務器端接收訪問令牌后,我想調用Google API獲取信息。 我可以在服務器端僅調用Google API,而無需插入API密鑰和其他憑證,而僅使用訪問令牌嗎?

像這樣:

plus.people.get({
    resourceName: 'people/me',
    personFields: 'emailAddresses,names',
    auth: accessToken}, (err, response) => {
      console.log(response);
    });

我實際上在使用node.js

我了解您想使用使用訪問令牌的people.get。 如果我的理解是正確的,那么該示例腳本如何?

示例腳本:

var google = require('googleapis');
var plus = google.people('v1');
var OAuth2 = google.auth.OAuth2;
var oauth2Client = new OAuth2();
oauth2Client.setCredentials({access_token: accessToken});
plus.people.get({
    resourceName: 'people/me',
    personFields: 'emailAddresses,names',
    auth: oauth2Client}, (err, response) => {
      console.log(response);
    });

如果我誤解了您的問題,對不起。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM