这是一个奇怪的问题,但是我在授权我刚刚创建的文件中(但没有其他任何文件)中访问Google Sheets API时遇到问题。
import FromMailToGoogle.uploadToDrive as uploadToDrive
from FromMailToGoogle import inputToSheets
GoogleDriveAuth = uploadToDrive.authenticate()
gc = inputToSheets.startAuthorization()
shortSheet = inputToSheets.startShortWorksheet(gc)
inputToSheets.py
def startAuthorization() -> object:
# json_key = json.load(open('client_secret.json')) # json credentials you downloaded earlier
scope = ['https://spreadsheets.google.com/feeds']
credentials = ServiceAccountCredentials.from_json_keyfile_name('sheets_credentials.json', scope)
gc = gspread.authorize(credentials)
return gc
我正在使用'inputToSheets`来授权对其他文件的访问而没有问题。
我得到的错误是:
gspread.exceptions.APIError: {
"error": {
"code": 403,
"message": "Google Sheets API has not been used in project 784047006277 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/sheets.googleapis.com/overview?project=784047006277 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
"status": "PERMISSION_DENIED",
"details": [
{
"@type": "type.googleapis.com/google.rpc.Help",
"links": [
{
"description": "Google developers console API activation",
"url": "https://console.developers.google.com/apis/api/sheets.googleapis.com/overview?project=784047006277"
}
]
}
]
}
}
它所引用的项目为784047006277
,我敢肯定我的帐户中根本没有该项目。我用来授权的JSON密钥的项目名称为gspread-xxxx
。那么,为什么它不在这里但在另一个文件中授权呢?
谢谢