通过服务器端数据API V3代表用户用服务账户上传视频至YouTube[英] Upload video to YouTube with a service account on behalf of a user by server side data API V3

本文是小编为大家收集整理的关于通过服务器端数据API V3代表用户用服务账户上传视频至YouTube的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我试图代表YouTube Data API V3上将视频上传到YouTube帐户,并收到'access_denied'错误. 根据Google文档:

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

  2. 我登录为'user@gmail.com',并给了我在步骤1中创建的" admin@gmail.com"服务帐户的许可. (在www.console.developers.google.com/permissions/projectpermissions'permissions'tab =>'添加成员')添加成员

这是我的请求(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)

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

另外,我找到了指向YouTube数据API -OAUTH 2.0流的链接,该链接可能表明该操作(通过服务帐户代表另一个用户导出到YouTube)不支持:www.developers.google.com/youtube/v3/指南/身份验证#oauth2_flows

会很感激您的回应!

推荐答案

YouTube API不支持您需要使用OAuth2的服务帐户.

本文地址:https://www.itbaoku.cn/post/1937739.html

问题描述

I am trying to upload a video to YouTube account on behalf of 'user@gmail.com' by YouTube data API V3 and I receive 'access_denied' error. According to google documentation:

  1. I opened a service account using a google administrator account 'admin@gmail.com' and completed the steps in : www.developers.google.com/identity/protocols/OAuth2ServiceAccount#delegatingauthority.

  2. I logged in as 'user@gmail.com' and gave permissions to 'admin@gmail.com' service account I created in step 1. (in www.console.developers.google.com/permissions/projectpermissions 'permissions' tab => 'add members') add member

This is my request (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();

And this is the response: 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)

Is it possible to upload video on behalf of users? Am I doing something wrong?

Also, I found a link to YouTube data API - Oauth 2.0 flows that may indicate that this operation (of exporting to YouTube on behalf of another user via service account) is not supported: www.developers.google.com/youtube/v3/guides/authentication#OAuth2_Flows

Would appreciate a lot your response!

推荐答案

The YouTube API doesn't support service accounts you need to use Oauth2.