반응형
Google API Python 라이브러리
pip install --upgrade google-api-python-client
예제 코드
# -*- coding: utf-8 -*-
# Sample Python code for youtube.subscriptions.insert
# 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 = "client_secret.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.subscriptions().insert(
part="snippet",
body={
"snippet": {
"resourceId": {
"kind": "youtube#channel",
# channel id
"channelId": "Channel ID"
}
}
}
)
response = request.execute()
print(response)
if __name__ == "__main__":
main()
반응형
'DEVEL > PYTHON' 카테고리의 다른 글
PYTHON ChatGPT API 예제 (0) | 2023.07.25 |
---|---|
PYTHON 내 주소에 이더리움 거래 조회 (0) | 2023.07.18 |
[PYTHON] requests 구글 검색 (0) | 2023.04.03 |
[PYTHON] selenium 구글 검색 (1) | 2023.04.03 |
Python 셀레니움으로 네이버 로그인하기 (0) | 2023.03.16 |