Issue in tagging gmail mails with gmail API chrome extension

73 views
Skip to first unread message

SSS

unread,
Nov 16, 2015, 1:23:21 AM11/16/15
to Google API JavaScript Client
I am trying to build a chrome extension for bulk tagging functionality by using gmail api. As there is no chance to build a button UI with gmail api I am using inboxsdk for button creation in gmail inbox and for bulk tagging functionality to work on button click I am using gmail api. In the sense when the button is clicked the selected mails should be tagged with the "general" label in gmail inbox. The button which I am using will be displayed next to delete button in existing gmail scenario.
Actually I am facing issues when executing the code. I am getting the below error

Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' 'sha256-Y+2PBkTuXdKc9Mz9jB6CV7zSLRMuViwjLM28phOgupM=' https://apis.google.com". Either the 'unsafe-inline' keyword, a hash ('sha256-3Q1MaJvQgJ6teNTlDmo181dGqOU1hK5uGmE5FYbL7is='), or a nonce ('nonce-...') is required to enable inline execution.

I am posting the code below.

manifest.json:


 
{

"name": "Gmail Extension",
"description": "Extension for tagging",
"version": "0.1",
"manifest_version": 2,
"minimum_chrome_version": "29",
"background": {
"page": "index.html"
 
},
"content_scripts": [
{
"matches": [
"https://mail.google.com/*",
"https://inbox.google.com/*"],
"js": ["inboxsdk.js", "alertify/alertify.min.js", "tag.js"],
"css": ["alertify/alertify.default.css", "alertify/alertify.core.css"],
"run_at": "document_end"
}],
"web_accessible_resources": ["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-pomd352gi79664h9tf0hg1uu160s4hop.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>
<meta charset='utf-8' />
<script src = "inboxsdk.js" </script>
<script src = "tag.js" </
script>
<script>
var CLIENT_ID = '763145023672-pomd352gi79664h9tf0hg1uu160s4hop.apps.googleusercontent.com';
var API KEY = 'AIzaSyC4i08lFNOYmx48lCiunLMV-KwnOey0vvw';
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
();
}
<script type="text/javascript" src="https://apis.google.com/js/client.js?onload=checkAuth"></script>
</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>


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('tag.png'),
onClick: tagThread(event){
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);
});
}

Can anyone please check and suggest on how to solve the error and execute successfully.

Reply all
Reply to author
Forward
0 new messages