使用 Google API 的 CLI 应用程序
CLI application using Google APIs
我想创建一个应用程序来下载我在 Google 照片中的所有照片。我认为使用 API 应该很容易。
这应该是一个 CLI 应用程序,它将 运行 从 cron 定期执行。
但是当我查看 Google 照片 API 时,他们使用 OAuth2。
该示例显示了 FixedCredentials 的用法:
PhotosLibrarySettings settings =
PhotosLibrarySettings.newBuilder()
.setCredentialsProvider(
FixedCredentialsProvider.create(/* Add credentials here. */))
.build();
问题出在 /* Add credentials here. */
所在的部分。我如何在那里提供我的用户凭据?有许多 类 实现了 Credentials
,但其中 none 看起来可以让我在 CLI 应用程序中自动检索。
我从 Google 得到的唯一东西是我的应用程序的 client_id 和 client_token,但如何将其转换为 access/refresh 令牌以便我可以使用没有我的互动?
我真的希望我不需要启动网络浏览器来下载我的照片。
Google 照片库 API 仅接受 OAuth 用户凭据。这意味着用户需要完成 Google OAuth Flow,即基于浏览器的授权。
Note: The Library API does not support service accounts. Your
application must use the other OAuth 2.0 flows available such as OAuth
2.0 for web server applications or OAuth 2.0 for mobile and desktop apps.
Your application must use OAuth 2.0 to authorize requests. No other
authorization protocols are supported. If your application uses Google
Sign-In, some aspects of authorization are handled for you.
此链接详细说明了这些要求:
我想创建一个应用程序来下载我在 Google 照片中的所有照片。我认为使用 API 应该很容易。
这应该是一个 CLI 应用程序,它将 运行 从 cron 定期执行。 但是当我查看 Google 照片 API 时,他们使用 OAuth2。 该示例显示了 FixedCredentials 的用法:
PhotosLibrarySettings settings =
PhotosLibrarySettings.newBuilder()
.setCredentialsProvider(
FixedCredentialsProvider.create(/* Add credentials here. */))
.build();
问题出在 /* Add credentials here. */
所在的部分。我如何在那里提供我的用户凭据?有许多 类 实现了 Credentials
,但其中 none 看起来可以让我在 CLI 应用程序中自动检索。
我从 Google 得到的唯一东西是我的应用程序的 client_id 和 client_token,但如何将其转换为 access/refresh 令牌以便我可以使用没有我的互动?
我真的希望我不需要启动网络浏览器来下载我的照片。
Google 照片库 API 仅接受 OAuth 用户凭据。这意味着用户需要完成 Google OAuth Flow,即基于浏览器的授权。
Note: The Library API does not support service accounts. Your application must use the other OAuth 2.0 flows available such as OAuth 2.0 for web server applications or OAuth 2.0 for mobile and desktop apps.
Your application must use OAuth 2.0 to authorize requests. No other authorization protocols are supported. If your application uses Google Sign-In, some aspects of authorization are handled for you.
此链接详细说明了这些要求: