I am trying to create an extension that uses the selected data and saves it to google sheets. Sounds pretty simple though but I am stuck at the Auth2 part.
Here's what I have done so far:
I have created a manifest.json
and uploaded it on the chrome developer dashboard to obtain the "key" and "id".
Used the "id" to get the auth client id and added it to my manifest.json
.
Next I have added basic html in "popup.html" and the context menu code part in "options.js" which is defined as the background script in "manifest.json".
Next I am using the "getAuthToken " to get the token in "popup.js". When I run the extension everything works but once I click the button to get the token nothing happens and "undefined" token value is returned.The error message is
Unchecked runtime.lastError while running identity.getAuthToken: OAuth2 request failed: Service responded with error: 'Service has been disabled for this account.'
Manifest.json
{
"name":"ext1",
"manifest_version":2,
"version": "1.0",
"description":"",
"browser_action":{
"default_icon":"icon48.png",
"default_popup":"popup.html"
},
"permissions":[
"identity",
"https://*/*",
"http://*/*",
"contextMenus",
"https://accounts.google.com/o/oauth2/token",
"storage"
],
"background":{
"scripts":["options.js"],
"persistent":false
},
"content_security_policy":"script-src 'self' https://apis.google.com; object-src 'self'",
"oauth2":{
"client_id":"<>.apps.googleusercontent.com",
"scopes":[
"https://www.googleapis.com/auth/spreadsheets"
]
},
"key":"<>"}
Popup.html
<!doctype <!DOCTYPE html>
<html>
<head>
<title>text</title>
<script src="jquery-3.3.1.min.js"></script>
<script src="popup.js"></script>
</head>
<body>
<h1>random text</h1>
<h2> Data: <span id="data"></span></h2>
<input type="submit" id="button" value="Authorize">
</body>
</html>
popup.js
$(function(){
chrome.storage.sync.get('datas', function(values){
$('#data').text(values.datas);
})
$("#button").on("click",function(){
chrome.identity.getAuthToken({"interactive":true},function(token){
alert("getting token......")
console.log("token")
console.log(token);
})
})
})
I have tried searching for similar issues but none solves my issue. kindly help what I am doing wrong.