在为chrome扩展运行identity.getAuthToken时,错误“此帐户已禁用服务”

问题描述 投票:1回答:2

我正在尝试创建一个使用所选数据并将其保存到Google工作表的扩展程序。听起来很简单,但我被困在Auth2部分。

这是我到目前为止所做的:

我创建了一个manifest.json并将其上传到chrome开发人员仪表板上以获取“密钥”和“id”。

使用“id”获取auth客户端ID并将其添加到我的manifest.json

接下来,我在“popup.html”中添加了基本的html,在“options.js”中添加了上下文菜单代码部分,后者被定义为“manifest.json”中的后台脚本。

接下来我使用“getAuthToken”来获取“popup.js”中的标记。当我运行扩展时一切正常但是一旦我点击按钮获取令牌没有任何反应并返回“未定义”令牌值。错误消息是

运行identity.getAuthToken时未经检查的runtime.lastError:OAuth2请求失败:服务响应错误:“此帐户已禁用服务”。

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);
        })
    })
})

我试过寻找类似的问题,但没有解决我的问题。请帮助我做错了。

google-chrome-extension oauth-2.0 google-api google-sheets-api google-oauth2
2个回答
1
投票

您可以参考此link中的建议来使其工作:

  1. 转到Google Developers Console并创建一个新项目。
  2. 转到面板中的API&auth> Credentials以创建新的客户端ID。如果您的应用已上传,则可以从Chrome Developer Dashboard获取Chrome应用的应用ID。
  3. 转到API&auth>同意屏幕并填写电子邮件地址和产品名称并保存。

1
投票

听起来您使用的帐户已启用Google advanced protection,该帐户会禁用gmail并为非Google应用启用相关的API访问权限:

为确保您的数据安全,大多数非Google应用和服务都无法访问您Google帐户中的某些数据,例如Google云端硬盘或Gmail。 *

© www.soinside.com 2019 - 2024. All rights reserved.