Reputation: 201
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.'
{
"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":"<>"}
<!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>
$(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.
Upvotes: 3
Views: 2302
Reputation: 1
okay, I encoutnered the same error and found the solution after 2 weeks investigation.
the solution is
this should solve the problem. Note: make sure that the manifest.json has the correct values for all fields.
Upvotes: 0
Reputation: 13495
You may be using an account with Google advanced protection which disables Gmail and Google Drive related API access for non-Google apps:
To keep your data secure, most non-Google apps and services won’t be able to access some data in your Google Account, like Google Drive or Gmail. *
Also see this announcement from Google: https://cloud.google.com/blog/products/identity-security/enhancing-security-controls-for-google-drive-third-party-apps
Today we’re announcing plans to extend the same policy to Google Drive as part of Project Strobe.
With this updated policy, we’ll limit the types of apps that have broad access to content or data via Drive APIs.
Upvotes: 2
Reputation:
Using another Google Account to sign in have worked for me and fixed the issue.
Upvotes: 0
Reputation: 13469
You may refer with the suggestion in this link to make it work:
- Go to Google Developers Console and create a new project.
- Go to APIs & auth > Credentials in the panel to create new Client ID. The application ID of chrome app can be obtained from Chrome Developer Dashboard if your app is uploaded.
- Go to APIs & auth > Consent screen and fill in Email Address and Product Name and Save.
Upvotes: 1