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

时间:2016-03-10 12:48:42

标签: java api youtube-api youtube-data-api google-oauth2

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

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

  2. 我以' user@gmail.com'登录;并授予' admin@gmail.com'我在步骤1中创建的服务帐户。 (在www.console.developers.google.com/permissions/projectpermissions'权限' tab =>'添加成员')add member

  3. 这是我的要求(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

    非常感谢您的回复!

1 个答案:

答案 0 :(得分:0)

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