async def _auth(client, message): creds = db.get_credential(message.from_user.id) if creds is not None: creds.refresh(Http()) db.set_credential(message.from_user.id, creds) await message.reply_text("🔒 **Already authorized your Google Drive Account.**\n__Use /revoke to revoke the current account.__\n__Send me a direct link or File to Upload on Google Drive__", quote=True) else: global flow try: flow = OAuth2WebServerFlow( G_DRIVE_CLIENT_ID, G_DRIVE_CLIENT_SECRET, OAUTH_SCOPE, redirect_uri=REDIRECT_URI ) auth_url = flow.step1_get_authorize_url() await client.send_message(message.from_user.id, "⛓️ **To Authorize your Google Drive account visit this [URL]({}) and send the generated code here.**\n__Visit the URL > Allow permissions > you will get a code > copy it > Send it here__".format(auth_url)) except Exception as e: await message.reply_text(f"**ERROR:** ```{e}```", quote=True)
async def _token(client, message): token = message.text.split()[-1] WORD = len(token) if WORD == 57 and token[1] == "/": creds = None global flow if flow is None: await message.reply_text( text="❗ **Invalid Code**\n__Run /auth first.__", quote=True ) return try: m = await message.reply_text(text="**Checking received code...**", quote=True) creds = flow.step2_exchange(message.text) db.set_credential(message.from_user.id, creds) await m.edit('**Authorized Google Drive account Successfully.**') flow = None except FlowExchangeError: await m.edit('❗ **Invalid Code**\n__The code you have sent is invalid or already used before. Generate new one by the Authorization URl__') except Exception as e: await m.edit(f"**ERROR:** ```{e}```")