首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Google API (Sheets) API错误代码403。权限不足:请求的身份验证范围不足

Google API (Sheets) API错误代码403。权限不足:请求的身份验证范围不足
EN

Stack Overflow用户
提问于 2019-07-03 00:52:00
回答 4查看 10.4K关注 0票数 3

我正在尝试一个项目,在这个项目中我可以使用python (我在Anaconda上使用jupyter笔记本)来读取google sheets中的数据。我看了一些视频和指南,并复制了代码。但是,我无法让代码正常工作

代码语言:javascript
运行
复制
import pandas as pd
import gspread
from oauth2client.service_account import ServiceAccountCredentials
scope = ['https://spreadsheets.google.com/feeds','https://www.googleapis.com/auth/drive']
creds = ServiceAccountCredentials.from_json_keyfile_name('test.json',scope)
client = gspread.authorize(creds)
data = gc.open('TEST').sheet1
print(data.get_all_records())

我得到的错误信息是

代码语言:javascript
运行
复制
APIError: {
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "insufficientPermissions",
    "message": "Insufficient Permission: Request had insufficient authentication scopes."
   }
  ],
  "code": 403,
  "message": "Insufficient Permission: Request had insufficient authentication scopes."
 }
}

对我应该做什么有什么建议吗?

EN

回答 4

Stack Overflow用户

发布于 2019-12-25 10:58:02

身份验证范围允许您的应用程序使用OAuth2身份验证在服务上执行某些操作。使用google API时,请参考Google API scopes sheet

请参阅下面image.Please中与Google V4相关的作用域,确保不要授予额外的权限,这可能会影响应用程序的安全性。

请注意:由于您计划更改作用域,请首先删除在本地项目文件夹中创建的token.json文件,然后再次允许访问您的应用程序。这将创建一个新的token.json文件。

票数 6
EN

Stack Overflow用户

发布于 2020-04-22 01:42:04

我在github上看到了一种使用google lib的新方式。这样做

代码语言:javascript
运行
复制
import gspread
from google.oauth2.service_account import Credentials

scope = ['https://spreadsheets.google.com/feeds',
         'https://www.googleapis.com/auth/drive']

creds = Credentials.from_service_account_file('client_secret.json', scopes=scope)

client = gspread.authorize(creds) 

我使用了这个链接:https://github.com/burnash/gspread

票数 2
EN

Stack Overflow用户

发布于 2019-09-01 07:26:18

不要忘记允许访问您从API dashboard下载的credentials.json中声明的电子邮件(client_email)的工作表:

代码语言:javascript
运行
复制
{
  "type": "service_account",
  "project_id": "XXXXXXXXXXX",
  "private_key_id": ".........",
  "private_key": .........
  "client_email": "getgooglesheets@xxxxxxxxxx.iam.gserviceaccount.com",
  "client_id": "..............",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  .......
}

我的意思是,你应该去你的谷歌工作表文件,并手动允许访问这封电子邮件。这在我的情况下工作得很好。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56857018

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档