chrome extension : OAuth2 request failed: Service responded with error: ‘bad request’

I have uploaded my extension to web-store and my extensions IDs are same on web-store dashboard and in local installation. I have also setup my credentials on google-api against chrome-app and put client_id in the manifest and set permission for “identity”.

When I call chrome.identity.getAuthToken , it returns this error OAuth2 request failed: Service responded with error: 'bad request' .. no more clues

Error ‘Service has been disabled for this account’ while running identity.getAuthToken for chrome extension

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

 


    text
    
    




random text

Data:

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.

How to change the download folder in Google Chrome Extension?

When downloading a file, I specify the file name like this:

chrome.downloads.onDeterminingFilename.addListener

But you need to change the file save folder. Actually the question is: how can this be done? What method to use?
The only thing I’ve come up with is to cancel the download and start a new one in the right folder.

Google API Key invalid

I’m developing a chrome extension application and so I’ve already created an API key and OAuth2 Client ID, and I’ve been able to get google drive files with no problem, but when I try accessing a spreadsheet I just get this error saying my API key is invalid. I’ve included all the necessary scopes, made sure that Google Drive and Google sheets are enabled, and deleted and recreated my API key, but still get this same error. Please help.

  window.onload = function() {
document.getElementById('pi').addEventListener('click', function() {
  chrome.identity.getAuthToken({interactive: true}, async function(token){

    //setToken(token);
    let init = {
      method: 'GET',
      async: true,
      headers: {
        Authorization: 'Bearer ' + token,
        'Content-Type': 'application/json'
      },
      'contentType': 'json'
    };
    //var theFoundURL = await getUrl2();
    //console.log("THE FOUND URL: " + theFoundURL);
    fetch(
        "https://sheets.googleapis.com/v4/spreadsheets/1b9NsKlhFeCDHXHGekQjhVxRmKfnijRs8Mkx9RFr9DIs/values/Sheet1A1%3AB1?key={MYAPIKEY}",
        init)
        .then((response) => response.json())
        .then(function(data) {
          console.log(data)
          let nowD = "1"; //getDate();
          if(nowD != data[0]){
              console.log("FALSE");
          }

          else console.log("TRUE");
        });




});

  }
  );
}

Javascript^

{

"manifest_version": 2,

"name": "G",
"version": "1.0",



"browser_action":{
"default_icon": "icon.png",
"default_popup": "popup.html"
},

"content_security_policy": "script-src 'self' https://ajax.googleapis.com; object-src 'self'",


"permissions": [
    "tabs",
    "storage",
    "activeTab",
    "alarms",
    "identity"
    ],

"oauth2": {
    "client_id": "MYID",

    "scopes": [
        "https://www.googleapis.com/auth/drive.file",
        "https://www.googleapis.com/auth/drive.readonly",
        "https://www.googleapis.com/auth/drive.metadata.readonly",
        "https://www.googleapis.com/auth/drive.metadata",
        "https://www.googleapis.com/auth/drive.appdata",    
        "https://www.googleapis.com/auth/drive",
        "https://www.googleapis.com/auth/spreadsheets",
        "https://www.googleapis.com/auth/spreadsheets.readonly"
    ]
},

"key": "MYKEY"

}

Manifest.json ^

  
    
      Spreadsheet Test
      
      
      
    
    
      
      

Popup.html^

1.
Initial state before logging into chrome and allowing access

2.
After first click on test button, I am redirected to signing into google chrome and authorizing for my extension to have access to my google drive and google sheets

3.
Next after the extension has access, I click the Test button again and in the console this error appears saying my API key is invalid

EDIT:

Sorry for the lack of clarity with my issue. The desired behavior I want is for my extension to retrieve the text in a particular cell of a user’s Google spreadsheet, but the issue I’m facing with is when I test it with my account and define the specific spreadsheet to retrieve data from, my extension is not allowed access to it. I’m still having this problem and am still very stuck. Also like I said before, I have used the same JavaScript format/syntax in my extension to access files on my google drive and get perfect results with no issues. I’ve added the necessary scopes for using Google Spreadsheets in their API reference website. If you can at least identify my issue it would be greatly appreciated.

function findSpreadSheet(token){
    theSpreadsheetUrl = null;
    let init = {
      method: 'GET',
      async: true,
      headers: {
        Authorization: 'Bearer ' + token,
        'Content-Type': 'application/json'
      },
      'contentType': 'json'
    };


    return new Promise( function (resolve, reject) {

        fetch(
        "https://www.googleapis.com/drive/v3/files?q=mimeType%3D'application%2Fvnd.google-apps.spreadsheet'&key={MYAPIKEY}",
        init)
        .then((response) => response.json())
        .then(function(data) {
          console.log(data)

          for(let i = 0; i < data.files.length; i++) {
              if(SEARCH_FOR == data.files[i].name){
                  theSpreadsheetUrl = data.files[i].id;
                  console.log("NOW");
                  console.log(theSpreadsheetUrl);
                  resolve(theSpreadsheetUrl);
              }
          }

          reject(null);
        });
    });

  }

^ my working javascript that I use to retrieve google drive files in case you were wondering

error : {code: 400, message: “API key not valid. Please pass a valid API key.”

I’m developing a chrome extension application and so I’ve already created an API key and OAuth2 Client ID, and I’ve been able to get google drive files with no problem, but when I try accessing a spreadsheet I just get this error saying my API key is invalid. I’ve included all the necessary scopes, made sure that Google Drive and Google sheets are enabled, and deleted and recreated my API key, but still get this same error. Please help.

  window.onload = function() {
document.getElementById('pi').addEventListener('click', function() {
  chrome.identity.getAuthToken({interactive: true}, async function(token){

    //setToken(token);
    let init = {
      method: 'GET',
      async: true,
      headers: {
        Authorization: 'Bearer ' + token,
        'Content-Type': 'application/json'
      },
      'contentType': 'json'
    };
    //var theFoundURL = await getUrl2();
    //console.log("THE FOUND URL: " + theFoundURL);
    fetch(
        "https://sheets.googleapis.com/v4/spreadsheets/1b9NsKlhFeCDHXHGekQjhVxRmKfnijRs8Mkx9RFr9DIs/values/Sheet1A1%3AB1?key={MYAPIKEY}",
        init)
        .then((response) => response.json())
        .then(function(data) {
          console.log(data)
          let nowD = "1"; //getDate();
          if(nowD != data[0]){
              console.log("FALSE");
          }

          else console.log("TRUE");
        });




});

  }
  );
}

Javascript^

{

"manifest_version": 2,

"name": "G",
"version": "1.0",



"browser_action":{
"default_icon": "icon.png",
"default_popup": "popup.html"
},

"content_security_policy": "script-src 'self' https://ajax.googleapis.com; object-src 'self'",


"permissions": [
    "tabs",
    "storage",
    "activeTab",
    "alarms",
    "identity"
    ],

"oauth2": {
    "client_id": "MYID",

    "scopes": [
        "https://www.googleapis.com/auth/drive.file",
        "https://www.googleapis.com/auth/drive.readonly",
        "https://www.googleapis.com/auth/drive.metadata.readonly",
        "https://www.googleapis.com/auth/drive.metadata",
        "https://www.googleapis.com/auth/drive.appdata",    
        "https://www.googleapis.com/auth/drive",
        "https://www.googleapis.com/auth/spreadsheets",
        "https://www.googleapis.com/auth/spreadsheets.readonly"
    ]
},

"key": "MYKEY"

}

Manifest.json ^

Will it be possible to use the chrome.identity after removing support for Chrome Apps?

In the extension for Chrome, which I develop, we need to use user authorization in the Google Drive service. I found a good client solution based on the chrome.identity API.

But in the documentation here I found the following warning:

Important: Chrome will be removing support for Chrome Apps on Windows, Mac, and Linux. Chrome OS will continue to support Chrome Apps. Additionally, Chrome and the Web Store will continue to support extensions on all platforms.

In this regard, the question:
Will I still be able to continue using chrome.identity API after removing support for Chrome Apps?
Or will it be necessary to seek another solution to this problem?

Google Chrome Extension Identity API Authentication

I’m having issues with my authentication on a Chrome Extension that I am working on to learn. Currently, my extension works for my profiles if users are logged in. As soon as I test this (by giving another party access), the extension does not seem to authorize. Am I doing something wrong here?

Could the below code be causing the issues with authentication? To give some context, this is in the background.js file of my extension.

function auth(token){
  chrome.identity.getAuthToken({ 'interactive': true }, function (token) {

if (chrome.runtime.lastError) {
  console.log(chrome.runtime.lastError);
  //Push Manual Authorise Button to UI
} else {
  //Authorised
  console.log('Token acquired: ' + token +
    ' See chrome://identity-internals for details.');
  classroomsExist(token);
}
return token;
  });
}

Enable Google API for “googleapis.com/auth/userinfo”

I am developing a Google Chrome Extension. I would like to be able to access the user profile info, using the data from these endpoints:

https://www.googleapis.com/auth/userinfo

https://www.googleapis.com/oauth2/v1/userinfo

I don’t seem to have access to these resources. From my web searches, it looks like I may need to enable a library API in the Google Developers Console. But I looked there and cannot find an appropriate API to enable. Does anyone know which API I should enable?

how to save string value and print it on antoher page using using google chrome storage api

I am looking to take user input in and then saving that user input using the google chrome storage api but I cannot find any useful reasources on this topic.

I have 2 elements that I would wish to save permanently using JS:

 var title = encodeURIComponent(document.getElementById('title').value);
var url = encodeURIComponent(document.getElementById('url').value);

I want to create an 2 arrays, one that holds the title values and one that holds the url values, then I want to print those values out on another page.

How to save String value and print it on another page using Google Chrome storage API

I am looking to take user input in and then saving that user input using the google chrome storage api but I cannot find any useful reasources on this topic.

I have 2 elements that I would wish to save permanently using JS:

 var title = encodeURIComponent(document.getElementById('title').value);
var url = encodeURIComponent(document.getElementById('url').value);

I want to create an 2 arrays, one that holds the title values and one that holds the url values, then I want to print those values out on another page.