So I am trying to create a Discord bot that can create and update playlists with the youtube API. However when I go to create the playlist it say's i need to visit a URL to authorize this application, eg.
Please visit this URL to authorize this application: https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=523005278110-dudud40lafimhbq73h9kcamc39g14eqv.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fyoutube.force-ssl&state=MCgahMYze4U8Tgx35u2TGGjPdXg3fZ&prompt=consent&access_type=offline
How would I make it so this doesnt happen, and my bot has access to the account to create playlists whenever it needs to?
//client_secrets has client_id and client_secret
CLIENT_SECRETS_FILE = 'client_secret.json'
SCOPES = ['https://www.googleapis.com/auth/youtube.force-ssl']
API_SERVICE_NAME = 'youtube'
API_VERSION = 'v3'
//This should authorize me but isn't or i've done it wrong
def get_authenticated_service():
flow = InstalledAppFlow.from_client_secrets_file(CLIENT_SECRETS_FILE, SCOPES)
credentials = flow.run_console()
return build(API_SERVICE_NAME, API_VERSION, credentials = credentials)
//This creates the playlist
def add_playlist(youtube, args):
body = dict(
snippet=dict(
title=args[0],
description=args[1]
),
status=dict(
privacyStatus='public'
)
)
playlists_insert_response = youtube.playlists().insert(
part='snippet,status',
body=body
).execute()
print('New playlist ID: %s' % playlists_insert_response['id'])
//This is the discord.py code that is called, and then calls the playlist creation code.
class SimpleCog:
"""SimpleCog"""
def __init__(self, bot):
self.bot = bot
@commands.command(name='newPlaylist', aliases=['np','new'])
@commands.guild_only()
async def newPlaylist(self, ctx, *, operand: str):
playlistName=operand.split()[0]
playlistDesc = "Playlist created by {0.name}#{0.discriminator} for server {1}".format(ctx.author,ctx.guild)
args = [playlistName,playlistDesc]
youtube = get_authenticated_service()
try:
add_playlist(youtube, args)
except HttpError as e:
await ctx.send('An HTTP error %d occurred:\n%s' % (e.resp.status, e.content))