嗨,实际上我正在尝试使用gmail api为批量标记功能构建chrome扩展。由于没有机会使用gmail api构建按钮UI,我使用inboxsdk在gmail收件箱中创建按钮,并且使用批量标记功能来处理按钮点击我正在使用gmail api。在单击按钮的意义上,所选邮件应在gmail收件箱中标记为“常规”标签。我正在使用的按钮将显示在现有gmail场景中删除按钮旁边的gmail工具栏中。
现在我面临的问题是,当我调试代码时,我没有发现任何错误,但是当我尝试执行代码时。邮件会自动重定向到gmail登录页面,此登录页面每次都会重复。
现在我发布以下代码
的manifest.json:
{
"name": "Gmail Extension",
"description": "Extension for tagging",
"version": "0.1",
"manifest_version": 2,
"minimum_chrome_version": "29",
"background": {
"page": "/background/index.html"
},
"content_scripts": [{
"matches": [
"https://mail.google.com/*",
"https://inbox.google.com/*"
],
"js": ["/libs/inboxsdk.js", "/libs/alertify/alertify.min.js", "/contentScript/tag.js"],
"css": ["/libs/alertify/alertify.default.css", "/libs/alertify/alertify.core.css"],
"run_at": "document_end"
}],
"web_accessible_resources": ["/icons/tag.png", "*"],
"permissions": ["identity", "<all_urls>", "tabs", "webRequest", "webRequestBlocking", "https://accounts.google.com/*", "https://www.googleapis.com/*", "https://mail.google.com/",
"https://inbox.google.com/"
],
"content_security_policy": "script-src 'self' 'sha256-Y+2PBkTuXdKc9Mz9jB6CV7zSLRMuViwjLM28phOgupM=' https://apis.google.com; object-src 'self'",
"oauth2": {
"client_id": "763145023672-gblto66pc638n485lu08visrvpocfqbs.apps.googleusercontent.com",
"scopes": ["https://mail.google.com/",
"https://www.googleapis.com/auth/gmail.modify",
"https://www.googleapis.com/auth/gmail.labels",
"https://www.googleapis.com/auth/gmail.send"
]
}
}
的index.html:
<!DOCTYPE html>
<html>
<head>
<title>Extension for tagging</title>
<meta charset='utf-8' />
<script src = "auth.js" </script>
<script type="text/javascript" src="https://apis.google.com/js/client.js?onload=checkAuth"></script>
<script src = "/libs/inboxsdk.js" </script>
<script src = "/contentScript/tag.js" </script>
</head>
<body>
<div id="authorize-div" style="display: none">
<span>Authorize access to Gmail API</span>
<!--Button for the user to click to initiate auth sequence -->
<button id="authorize-button" onclick="handleAuthClick(event)">
Authorize
</button>
</div>
</body>
</html>
auth.js:
var CLIENT_ID = '763145023672-gblto66pc638n485lu08visrvpocfqbs.apps.googleusercontent.com';
var SCOPES = [
'https://mail.google.com/',
'https://www.googleapis.com/auth/gmail.modify',
'https://www.googleapis.com/auth/gmail.labels',
'https://www.googleapis.com/auth/gmail.send'
];
function checkAuth() {
gapi.auth.authorize({
'client_id': CLIENT_ID,
'scope': SCOPES,
'immediate': true
},
handleAuthResult);
}
function handleAuthResult(authResult) {
var authorizeDiv = document.getElementById('authorize-div');
if (authResult && !authResult.error) {
// Hide auth UI, then load client library.
authorizeDiv.style.display = 'none';
loadGmailApi();
} else {
// Show auth UI, allowing the user to initiate authorization by
// clicking authorize button.
authorizeDiv.style.display = 'inline';
}
}
function handleAuthClick(event) {
gapi.auth.authorize({
'client_id': CLIENT_ID,
'scope': SCOPES,
'immediate': false
},
handleAuthResult);
return false;
}
function loadGmailApi() {
gapi.client.load('gmail', 'v1', updateLabel);
updateLabel();
}
tag.js:
function updateLabel() {
var request = gapi.client.gmail.users.labels.update({
'userId': 'me'
});
request.execute(function(resp) {
function whenNoneSelected(route) {
return false;
}
function register(sdk) {
sdk.Toolbars.registerToolbarButtonForList({
title: 'General',
section: sdk.Toolbars.SectionNames.INBOX_STATE,
iconUrl: chrome.extension.getURL('/icons/tag.png'),
onClick: tagThread() {
var label = GmailApp.getUserLabelByName("General");
var threads = label.getThreads(); // var threads = GmailApp.getThreads();
for (var i = 0; i < threads.length; i++) {
//add label "General" for selected threads
threads[i].addLabel(label);
}
alertify.success('Threads tagged as General');
},
hasDropdown: false,
hideFor: whenNoneSelected,
keyboardShortcutHandle: null
});
}
InboxSDK.load('1', 'sdk_mailtag_fd47af3e65').then(register);
});
}
replacedtag.js:
function whenNoneSelected(route) {
return false;
}
function register(sdk) {
function tagThread(event) {
alertify.success('Threads marked as General');
}
sdk.Toolbars.registerToolbarButtonForList({
title: 'General',
section: sdk.Toolbars.SectionNames.INBOX_STATE,
iconUrl: chrome.extension.getURL('/icons/tag.png'),
onClick: tagThread,
hasDropdown: false,
hideFor: whenNoneSelected,
keyboardShortcutHandle: null
});
}
InboxSDK.load('1', 'sdk_mailtag_fd47af3e65').then(register);
任何有相关解决方案的人都将不胜感激。