'Create playlist by youtube data API (python)
I want to create a python project to manage your playlist, but I'm having truble creating a new playlist, my code below:
from google_auth_oauthlib.flow import InstalledAppFlow
import googleapiclient.discovery
scopes = ["https://www.googleapis.com/auth/youtube.force-ssl"]
client_secrets_file = "client_secret.json"
# Get credentials and create an API client
flow = InstalledAppFlow.from_client_secrets_file(client_secrets_file, scopes)
credentials = flow.run_console()
youtube = googleapiclient.discovery.build("youtube", "v3", credentials=credentials)
request = youtube.playlists().insert(
part="snippet",
body={
"snippet": {
"title": "new playlist",
}
}
)
response = request.execute()
The Error:
googleapiclient.errors.HttpError: <HttpError 401 when requesting https://youtube.googleapis.com/youtube/v3/playlists?part=snippet&alt=json returned "Unauthorized". Details: "[{'message': 'Unauthorized', 'domain': 'youtube.header', 'reason': 'youtubeSignupRequired', 'location': 'Authorization', 'locationType': 'header'}]">
I think it's because I didn't have the API key, but it still occurs anyways.
Can someone help me @_@
Solution 1:[1]
I figured it out myself, the error occurs because I used the organization account from google to create my project’s OAuth Authorization, which is not available for create a new playlist, so I create another project with a normal Google account, and it works perfectly normal.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | adamaconguli |