I have been working on this problem for a while,
I am using youtube API to list out all playlist items in a channel, I have read this below: Youtube Data API - How to avoid Google OAuth redirect URL authorization
But I still need to open the browser and auth my program to access my own youtube account every time I run it.
According to this page: https://developers.google.com/youtube/v3/getting-started
4. If your application will use any API methods that require user authorization,
read the authentication guide to learn how to implement OAuth 2.0 authorization.
All I need is listing all available video in a channel.
Code examples provided by google:
import os
import google_auth_oauthlib.flow
import googleapiclient.discovery
import googleapiclient.errors
from google_auth_oauthlib.flow import Flow
scopes = ["https://www.googleapis.com/auth/youtube.readonly"]
def main():
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"
api_service_name = "youtube"
api_version = "v3"
client_secrets_file = "CREDFILE.json"
# Get credentials and create an API client
flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(
client_secrets_file, scopes)
credentials = flow.run_console()
youtube = googleapiclient.discovery.build(
api_service_name, api_version, credentials=credentials)
request = youtube.playlistItems().list(
part="snippet",
maxResults=30,
playlistId="PLAYLISTID"
)
response = request.execute()
print(response)
if __name__ == "__main__":
main()
I have put my credential.json files as the code specified, but I still have to auth myself, then paste the auth code in the command line. I am confused about the use of supplying credential.json files here.
It seems like credentials = flow.run_console()
caused this,
could it be possible having other method to get the credential?
PlaylistItems.list
endpoint. – stvar