Skip to content

Instantly share code, notes, and snippets.

@eggman
Created April 4, 2020 15:00
Show Gist options
  • Select an option

  • Save eggman/ef19557cc5ae8ce1859e82fb2b9d51a0 to your computer and use it in GitHub Desktop.

Select an option

Save eggman/ef19557cc5ae8ce1859e82fb2b9d51a0 to your computer and use it in GitHub Desktop.

Revisions

  1. eggman created this gist Apr 4, 2020.
    11 changes: 11 additions & 0 deletions 00_readme.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    # Delete YouTube playlist item

    * python3

    ## prepare

    ```
    $ pip3 install google-api-client
    ```

    download YOUR_CLIENT_SECRET_FILE.json from gootle API page.
    39 changes: 39 additions & 0 deletions delete.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    # -*- coding: utf-8 -*-

    # Sample Python code for youtube.playlistItems.delete
    # See instructions for running these code samples locally:
    # https://developers.google.com/explorer-help/guides/code_samples#python

    import os

    import google_auth_oauthlib.flow
    import googleapiclient.discovery
    import googleapiclient.errors

    scopes = ["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.playlistItems().delete(
    id="UExUQ0NmYWlnRF84cTRzT1F6MXQ5bEdidER0TDBJdklmRy4wOTA3OTZBNzVEMTUzOTMy"
    )
    request.execute()

    if __name__ == "__main__":
    main()