![](/img/trans.png)
[英]Azure Functions and Google API with Google OAuth2 (node.js)
[英]Impersonate user with google calendar API oauth2 service account (node.js)
我試圖通過谷歌日歷API使用服務器進行服務器身份驗證。 在他們提到的文檔中,您可以冒充用戶。 我已將所有者權限添加到我要模擬的帳戶,並確保已啟用域范圍委派。 從我讀過的所有內容中,'user @ example'應該指定模仿,但它不起作用。 我有創建事件等工作的所有功能,但我無法從谷歌隨機生成的電子郵件中獲取它。
var google = require('googleapis');
var calendar = google.calendar('v3');
var scopes = ['https://www.googleapis.com/auth/calendar'];
var key = require ('./xxx.json'); // private json
console.log("Calendar Service connected");
var jwtClient = new google.auth.JWT(
key.client_email,
null,
key.private_key,
scopes,
'user@example.com'
);
jwtClient.authorize(function(err, token) {
if(err) {
//console.log(err);
}
console.log('token',token);
//listCalendars(jwtClient);
});
module.exports = {};
謝謝你的幫助!!
對於將來需要這個的人。 它開始工作后:
1)啟用域范圍授權2)將用戶添加到服務帳戶作為所有者3)可能最重要**:繼續谷歌管理員並給api訪問服務帳戶
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.