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

查看:124
本文介绍了通过服务器端数据API V3代表用户使用服务帐户将视频上传到YouTube的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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. 我使用Google管理员帐户"admin@gmail.com"开设了一个服务帐户,并完成了以下步骤:www.developers.google.com/identity/protocols/OAuth2ServiceAccount#delegatingauthority.

  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.

我以"user@gmail.com"身份登录,并授予了在步骤1中创建的"admin@gmail.com"服务帐户的权限. (在www.console.developers.google.com/permissions/projectpermissions权限"标签=>添加成员"中)

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

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

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?

我还找到了指向YouTube数据API的链接-Oauth 2.0流可能表明不支持该操作(代表另一用户通过服务帐户导出到YouTube):www.developers.google.com/youtube/v3/guides/authentication#OAuth2_Flows

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

非常感谢您的答复!

推荐答案

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

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

这篇关于通过服务器端数据API V3代表用户使用服务帐户将视频上传到YouTube的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆