gpt4 book ai didi

gmail-api - 如何在 chrome 扩展中使用 gmail api?

转载 作者:行者123 更新时间:2023-12-05 07:46:10 25 4
gpt4 key购买 nike

我是 chrome 扩展和 gmail api 的新手。我正在尝试在实现我的扩展时连接 gmail api。我有 API key 和客户端 ID。

最佳答案

在您的 list 中,您首先需要添加:

"background": {
"scripts": ["background.js" ,"client.js"]
},
"content_security_policy": "script-src https://*.google.com 'unsafe-eval'; object-src 'self'",
"oauth2": {
"client_id": "<your client id>",
"scopes": [
scope: 'https://mail.google.com/'
]
},

"permissions": [
"background",
"identity",
"tabs",
"https://www.googleapis.com/*",
"https://*.googleusercontent.com/*",
"https://mail.google.com/",
],

当 client.js 是 gmail API 库时...现在在你的后台页面你需要连接..我给你在 JS 中的例子:

chrome.identity.getAuthToken(
{'interactive': true},
function(token){
/// you can use the token( user token ) for create http request to gmail api
}
);

window.gapi_onload = function(){
gapi.client.setApiKey("<your api code>");

gapi.auth.authorize(
{
client_id: '<Your client id>',
immediate: true,
scope: "https://mail.google.com/",

},
function(){
gapi.client.load('gmail', 'v1', gmailAPILoaded);
}
);


}
function gmailAPILoaded(){
// Do things you want with gapi.client
}

我给你的大部分东西都是基于this guide但它并不适合我,所以我改变了一些东西。

祝你好运

关于gmail-api - 如何在 chrome 扩展中使用 gmail api?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41118712/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com