我得到了用于从 youtube 分析 api(不是 youtube 数据 API V3)中提取 youtube 信息的下一个代码
import os
import google_auth_oauthlib.flow
import googleapiclient.discovery
import googleapiclient.errors
scopes = ["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 = "youtubeAnalytics"
api_version = "v2"
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_analytics = googleapiclient.discovery.build(
api_service_name, api_version, credentials=credentials)
request = youtube_analytics.reports().query(
dimensions="video",
endDate="2014-06-30",
ids="channel==MINE",
maxResults=10,
metrics="estimatedMinutesWatched,views,likes,subscribersGained",
sort="-estimatedMinutesWatched",
startDate="2014-05-01"
)
response = request.execute()
print(response)
我得到了客户端密码并且代码运行良好,但是我在云上运行代码(特别是 deepnote)所以在某些时候代码需要手动输入令牌,有没有办法避免这种情况,或者提取令牌某种程度上来说?因为我认为在云上运行此代码时无法检索令牌。
提前致谢。