0

here is the way using youtube api to upload videos to the channel.

but my question is every time i run the code, it ask me to "Please visit this URL to authorize this application"

# -*- coding: utf-8 -*-

# Sample Python code for youtube.videos.insert
# NOTES:
# 1. This sample code uploads a file and can't be executed via this interface.
#    To test this code, you must run it locally using your own API credentials.
#    See: https://developers.google.com/explorer-help/guides/code_samples#python
# 2. This example makes a simple upload request. We recommend that you consider
#    using resumable uploads instead, particularly if you are transferring large
#    files or there's a high likelihood of a network interruption or other
#    transmission failure. To learn more about resumable uploads, see:
#    https://developers.google.com/api-client-library/python/guide/media_upload

import os

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

from googleapiclient.http import MediaFileUpload

scopes = ["https://www.googleapis.com/auth/youtube.upload"]

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 = "C:/Users/User/computer science/moviepy/client_secret_660339349555-der7rru7no2g1v4oe1o1g7qqm27ujodo.apps.googleusercontent.com.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.videos().insert(
        part = "snippet,status",
        
        body={
          "snippet": {
            "title": "test",
            "description": "四次是鬼"
          },
          "status": {
            "privacyStatus": "private"
          }
        },
        
        # TODO: For this request to work, you must replace "YOUR_FILE"
        #       with a pointer to the actual file you are uploading.
        media_body=MediaFileUpload("D:/Downloads/ytdl/wtf8.mp4")
    )
    response = request.execute()

    #print(response)

if __name__ == "__main__":
    main()

is there any way to prevent this situation?

i hope someone can solve my question, thanks.

Prisoner
  • 49,922
  • 7
  • 53
  • 105
  • This is the answer to your question: [How to bypass entering authentication code to authorize my code everytime I use the YouTube Data API v3](https://stackoverflow.com/a/64719550/8327971). – stvar Jul 28 '21 at 09:21
  • thanks, I really appreciate you to give me the solution. – Steve Deltora Jul 29 '21 at 12:13

0 Answers0