我一直在探索 YouTube 数据 API。我的项目的前提很简单:使用 API,进行身份验证(是的,我有帐户的凭据),然后简单地检索我所有视频的列表,公共和私人。
除了完全自动化的部分,我已经能够成功地完成这项工作。我使用了各种来源的代码,当我在命令行上运行它时,它为我提供了一个可在浏览器中使用的链接,以便进行授权。
它看起来像这样:
请访问此 URL 以授权此应用程序:https : //accounts.google.com/o/oauth2/auth?response_type=code&client_id=7932902759886-cb8ai84grcqshe24nn459ka46uh45ssj.apps.googleusercontent.com&redirect3Auriet%3Auth%Aurn3A %3Aoob&范围= HTTPS%3A%2F%2Fwww.googleapis.com%2Fauth%2Fyoutube.readonly&状态= zNVvgEyO47nmacvdEEAhDsQipY194k&提示=同意&ACCESS_TYPE =离线&code_challenge = aF7uTCghjwgwjg49o3fgiIU-_ryK19rDeX4l1uzr37w&code_challenge_method = S256 输入授权码:
....
这是我的python代码片段:
import google_auth_oauthlib.flow
import googleapiclient.discovery
import googleapiclient.errors
...
...
# 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)
## MAKE youtube SEARCH REQUEST
last_date = '2018-10-01T00:00:00Z'
request = youtube.search().list(
part="snippet",
forMine=True,
maxResults=50,
order="date",
type="video"
)
all_items = []
response = request.execute()
Run Code Online (Sandbox Code Playgroud)
我的问题如下:是否可以以编程方式执行授权,以便应用程序可以独立运行而不必等待此用户操作(从 …