为什么使用gspread会出现无效的作用域错误

问题描述 投票:1回答:1
import discord
from discord.ext import commands
import gspread
from oauth2client.service_account import ServiceAccountCredentials
from pprint import pprint

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

creds = ServiceAccountCredentials.from_json_keyfile_name("creds.json", scope)

client = gspread.authorize(creds)

sheet = client.open("NYRP Clock Ins").sheet1  # Open the spreadhseet

data = sheet.get_all_records()  # Get a list of all records

row = sheet.row_values(3)  # Get a specific row
col = sheet.col_values(3)  # Get a specific column
cell = sheet.cell(1,2).value  # Get the value of a specific cell

insertRow = ["hello", 5, "red", "blue"]
sheet.add_rows(insertRow, 4)  # Insert the list as a row at index 4

sheet.update_cell(2,2, "CHANGED")  # Update one cell

numRows = sheet.row_count  # Get the number of rows in the sheet

class MyClient(discord.Client):
    async def on_ready(self):
        print('Logged in as')
        print(self.user.name)
        print(self.user.id)
        print('------')

    async def on_message(self, message):
        # we do not want the bot to reply to itself
        if message.author.id == self.user.id:
            return

        if message.content.startswith('.clock in'):
            embed = discord.Embed(title='BCSO', description='Succesfully Clocked In', color=0x5ed623)
            embed.add_field(name='.clock out', value='Clocks out')
            await message.channel.send(content=None, embed=embed,)
            insertRow = ["hello", 5, "red", "blue"]
            sheet.add_rows(insertRow, 4)  # Insert the list as a row at index 4


        if message.content.startswith('.clock out'):
            embed = discord.Embed(title='BCSO', description='Succesfully Clocked Out', color=0xef210a)
            embed.add_field(name='.clock in', value='Clocks In')
            await message.channel.send(content=None, embed=embed,)

invalid_scope:https://spreadsheets.google.com/feeds",'https://www.googleapis.com/auth/sprea...,"https://www.googleapis.com/auth/drive...","https://www.googleapis.com/auth/ drive不是有效的受众群体字符串。

[当我尝试运行机器人并无法找到修复程序时,收到上述错误消息

python python-3.x google-apps-script google-sheets gspread
1个回答
0
投票
您使用的范围未正确定义。

您可以尝试以下方法:

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