通过服务器端数据代表用户使用服务帐户将视频上传到 YouTube API V3

Upload video to YouTube with a service account on behalf of a user by server side data API V3

我正尝试通过 YouTube 数据 API V3 代表 'user@gmail.com' 将视频上传到 YouTube 帐户,但我收到 'access_denied' 错误。 根据 google 文档:

  1. 我使用 google 管理员帐户 'admin@gmail.com' 开设了一个服务帐户,并完成了以下步骤:www.developers.google。com/identity/protocols/OAuth2ServiceAccount#delegatingauthority。

  2. 我以 'user@gmail.com' 身份登录并授予我在步骤 1 中创建的 'admin@gmail.com' 服务帐户的权限。 (在 www.console.developers.google.com/permissions/projectpermissions 'permissions' 选项卡 => 'add members')add member

这是我的要求 (JAVA) :

 youtube = new YouTube.Builder(
            GoogleAuthImpl.HTTP_TRANSPORT,
            GoogleAuthImpl.JSON_FACTORY,
            new GoogleCredential.Builder()
                    .setTransport(HTTP_TRANSPORT)
                    .setJsonFactory(JSON_FACTORY)
                    .setServiceAccountId("my-service-account@test.com")
                    .setServiceAccountPrivateKeyFromP12File(new File("my-service-account.p12"))
                    .setServiceAccountScopes(Collections.singleton(SQLAdminScopes.SQLSERVICE_ADMIN))
                    .setServiceAccountUser("user@email.com")
                    .build()
    )
            .setApplicationName("My App")
            .build();

这是回复:com.google.api.client.auth.oauth2.TokenResponseException: 403 Forbidden { "error" : "access_denied", "error_description" : "Requested client not authorized." } at com.google.api.client.auth.oauth2.TokenResponseException.from(TokenResponseException.java:105) at com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:287) at com.google.api.client.auth.oauth2.TokenRequest.execute(TokenRequest.java:307) at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.executeRefreshToken(GoogleCredential.java:384) at com.google.api.client.auth.oauth2.Credential.refreshToken(Credential.java:489) at com.google.api.client.auth.oauth2.Credential.intercept(Credential.java:217) at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:859) at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419) at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352) at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)

是否可以代用户上传视频?我做错了什么吗?

此外,我发现 link 到 YouTube 数据 API - Oauth 2.0 流程可能表明不支持此操作(通过服务帐户代表其他用户导出到 YouTube) : www.developers.google.com/youtube/v3/guides/authentication#OAuth2_Flows

非常感谢您的回复!

YouTube API 不支持您需要使用 Oauth2 的服务帐户。