Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3718

Youtube Data API - How to get my private and unlisted videos

$
0
0

Last year I was able to retrieve videos of all statuses (upon authenticating via OAuth) via Playlistitems > list specifying the playlist containing all uploads.

As of today, the same code only gives me public uploads:

import osimport google_auth_oauthlib.flowimport googleapiclient.discoveryimport googleapiclient.errorsscopes = ["https://www.googleapis.com/auth/youtube.readonly"]def main():    # Disable OAuthlib's HTTPS verification when running locally.    # *DO NOT* leave this option enabled in production.    os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"    api_service_name = "youtube"    api_version = "v3"    client_secrets_file = "CLIENT_SECRETS.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=50, playlistId="__PLAYLIST__ID")        response = request.execute()    total = response['pageInfo']['totalResults']    print("total number of videos is " + str(total));    exit();if __name__ == "__main__":    main()

I am aware that others have asked this question but they are either really old posts or not answered comprehensively.

The only other possibile method seems to be Search > list specifying the channel ID but this too only returned public videos despite authenticating via OAuth:

import osimport google_auth_oauthlib.flowimport googleapiclient.discoveryimport googleapiclient.errorsscopes = ["https://www.googleapis.com/auth/youtube.force-ssl"]def main():    # Disable OAuthlib's HTTPS verification when running locally.    # *DO NOT* leave this option enabled in production.    os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"    api_service_name = "youtube"    api_version = "v3"    client_secrets_file = "YOUR_CLIENT_SECRET_FILE.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.search().list(        part="snippet",        channelId="___CHANNEL__ID___",        type="video"    )    response = request.execute()    print(response)if __name__ == "__main__":    main()

The documentation claims that setting the forMine parameter:

[...] can only be used in a properly authorized request. The forMine parameter restricts the search to only retrieve videos owned by the authenticated user. If you set this parameter to true, then the type parameter's value must also be set to video.

However, this resulted in an invalid request when I included forMine set to true.

Any advice on how to currently get private / unlisted YouTube video data would be much appreciated.


Viewing all articles
Browse latest Browse all 3718

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>