问题描述
我试图通过YouTube数据API V3代表"[email protected]"将视频上传到YouTube帐户,但收到"access_denied"错误.根据Google文档:
I am trying to upload a video to YouTube account on behalf of '[email protected]' by YouTube data API V3 and I receive 'access_denied' error.According to google documentation:
-
我使用Google管理员帐户"[email protected]"开设了一个服务帐户,并完成了以下步骤:www.developers.google.com/identity/protocols/OAuth2ServiceAccount#delegatingauthority.
I opened a service account using a google administrator account '[email protected]' and completed the steps in : www.developers.google.com/identity/protocols/OAuth2ServiceAccount#delegatingauthority.
我以"[email protected]"身份登录,并授予了在步骤1中创建的"[email protected]"服务帐户的权限.(在www.console.developers.google.com/permissions/projectpermissions权限"标签=>添加成员"中)添加成员
I logged in as '[email protected]' and gave permissions to '[email protected]' 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("[email protected]")
.setServiceAccountPrivateKeyFromP12File(new File("my-service-account.p12"))
.setServiceAccountScopes(Collections.singleton(SQLAdminScopes.SQLSERVICE_ADMIN))
.setServiceAccountUser("[email protected]")
.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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!