gsheets.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:Tobo-Cogs 作者: Tobotimus 项目源码 文件源码
def authsheets(self, ctx):
        """Authorize GSheets to use the Google Sheets API."""
        flow = client.OAuth2WebServerFlow(**FLOW_KWARGS)
        authorize_url = flow.step1_get_authorize_url()
        info_message = ("Use the link below to authorize the cog to communicate with Google Sheets, "
                        "then copy the code you recieve and paste it here.")
        warn_message = ("**NOTE**: It is not recommended to authorize the cog using "
                        "your personal Google Account; it is best to create a new Google Account, "
                        "and share any Sheets you would like to access with that google account.")
        embed = discord.Embed(title="Authorize GSheets", url=authorize_url, description=warn_message)
        try:
            await self.bot.say(info_message, embed=embed)
        except discord.errors.Forbidden:
            await self.bot.say("\n\n".join(info_message, authorize_url, warn_message))
        resp = await self.bot.wait_for_message(author=ctx.message.author)
        credentials = None
        if resp:
            try:
                code = resp.content
                http = httplib2.Http()
                credentials = flow.step2_exchange(code, http=http)
            except client.FlowExchangeError as e:
                await self.bot.say("Authentication has failed: {}".format(e.args[0]))
                return
        self.gc = GSheetsClient(credentials)
        store = Storage(CREDENTIAL_PATH)
        store.put(credentials)
        credentials.set_store(store)
        await self.bot.say("Authentication successful.")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号