Python google api dict没有属性authorize
还有一个陷阱,但它甚至没有走那么远Python google api dict没有属性authorize,python,discord,google-sheets-api,Python,Discord,Google Sheets Api,还有一个陷阱,但它甚至没有走那么远 import discord import os import requests import json import random from jokeapi import Jokes import gspread from googleapiclient.discovery import build from google_auth_oauthlib.flow import InstalledAppFlow from google.auth.transpor
import discord
import os
import requests
import json
import random
from jokeapi import Jokes
import gspread
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
creedentials={has the appropriate stuff in it}
sh_id = "order_order_and_progress"
gc = gspread.service_account_from_dict(creedentials)
sh = gc.open(sh_id)
service = build('sheets', 'v4', credentials=creedentials)
sheet = service.spreadsheets()
def get_progress(rescue_ranges, sh_id):
result_shit = sheet.values().get(spreadsheetId=sh_id, range=rescue_ranges).execute()
value_dental = result_shit.get('values', [])
return(value_dental)
关于
它的意思是这行服务=build('sheets','v4',credentials=credentials)
,当我看到你的脚本时,service=build('sheets','v4',credentials=credentials)
的是credentials={里面有合适的东西}
。如果{包含适当的内容}
是服务帐户的JSON数据,包括私钥
,客户端电子邮件
等等,不幸的是,该值不能直接用于service=build('sheets',v4',credentials=credentials)
。我想这就是你的问题所在
当您想对服务帐户使用service=build('sheets','v4',credentials=credentials)
,并且credentials={包含适当的内容}
是服务帐户的JSON数据,包括私钥
,客户端电子邮件
等等,下面的修改如何?在这种情况下,请同时设置作用域
修改脚本1:
修改脚本2:
注:
- 两个示例都可以使用。所以请选择其中一个
- 在这次修改中,它是一个简单的示例脚本,用于将
service=build('sheets','v4',credentials=credentials)
与服务帐户的JSON数据一起使用,包括private\u key
,client\u email
等等。因此,请根据您的实际情况进行修改
- 而且,这个示例脚本使用
https://www.googleapis.com/auth/spreadsheets
。如果要使用其他作用域,请添加它们
参考资料:
你能提供你当前的脚本来复制你的问题吗?更新了,如果我需要发布更多,我会的,但是在我开始工作之前,整个机器人都在工作,包括$progress命令,直接拉电子表格值谢谢你的回复。您的脚本中哪里出现了错误'dict'对象没有属性'authorize'
?回溯是我所能找到的所有内容,在回溯的最后,它说它是这一行service=build('sheets','v4',credentials=credentials)
谢谢您的帮助!我至少可以打印我现在要求的范围!现在把它变成一个很好的列表哈哈。谢谢again@helmet648谢谢你的回复。我很高兴你的问题解决了。通过你的合作,我可以正确地理解。也谢谢你。
import discord
import os
import requests
import json
import random
from jokeapi import Jokes
import gspread
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
creedentials={has the appropriate stuff in it}
sh_id = "order_order_and_progress"
gc = gspread.service_account_from_dict(creedentials)
sh = gc.open(sh_id)
service = build('sheets', 'v4', credentials=creedentials)
sheet = service.spreadsheets()
def get_progress(rescue_ranges, sh_id):
result_shit = sheet.values().get(spreadsheetId=sh_id, range=rescue_ranges).execute()
value_dental = result_shit.get('values', [])
return(value_dental)
if message.content.startswith('$progress'):
beans = get_gif("working")
beaned = beans["results"][dummy]["url"]
# listed = get_progress(rescue_ranges, sh_id)
await (message.channel.send(TERG + ", Here\'s how things are looking \nhttp://alinktosomewhere.neat \n" + beaned))
from oauth2client.service_account import ServiceAccountCredentials
from googleapiclient.discovery import build
creedentials = {has the appropriate stuff in it}
credentials = ServiceAccountCredentials.from_json_keyfile_dict(creedentials, scopes=['https://www.googleapis.com/auth/spreadsheets'])
service = build('sheets', 'v4', credentials=credentials)
sheet = service.spreadsheets()
from google.oauth2 import service_account
from googleapiclient.discovery import build
creedentials = {has the appropriate stuff in it}
credentials = service_account.Credentials.from_service_account_info(creedentials, scopes=['https://www.googleapis.com/auth/spreadsheets'])
service = build('sheets', 'v4', credentials=credentials)