【发布时间】:2017-04-28 08:57:19
【问题描述】:
我是 chrome 扩展和 gmail api 的新手。 我正在尝试在实现我的扩展时连接 gmail api。 我有 api 密钥和客户端 ID。
【问题讨论】:
标签: gmail-api
我是 chrome 扩展和 gmail api 的新手。 我正在尝试在实现我的扩展时连接 gmail api。 我有 api 密钥和客户端 ID。
【问题讨论】:
标签: gmail-api
在您的清单中,您首先需要添加:
"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 给你的大部分东西,但它对我完全不起作用,所以我改变了一些东西。
祝你好运
【讨论】:
您不一定需要gapi.auth.authorize(...) 调用。改为寻找chrome.identity API。
【讨论】: