【发布时间】:2016-06-05 09:08:46
【问题描述】:
我正在尝试使用 Google 服务帐户列出来自 YouTube Data API v3 的视频。我激活了 YouTube API,创建了帐户服务,但每当我尝试列出我频道中的视频时,即使我上传了视频,它也会显示 0 个视频。
我从他们的文档中运行了示例,但我的凭据似乎直接从我的服务帐户中列出了视频,而不是我的真实 YouTube 帐户。
List<String> scopes = Lists.newArrayList("https://www.googleapis.com/auth/youtube");
JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId("youtube-****serviceaccount.com")
.setServiceAccountScopes(scopes)
.setServiceAccountPrivateKeyFromP12File(new File("C:\\tmp\\youtube.p12"))
.build();
youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential).setApplicationName(
"youtube-cmdline-uploadvideo-sample").build();
YouTube.Channels.List channelRequest = youtube.channels().list("contentDetails");
channelRequest.setMine(true);
ChannelListResponse channelResult = channelRequest.execute();
List<Channel> channelsList = channelResult.getItems();
String uploadPlaylistId = channelsList.get(0).getContentDetails().getRelatedPlaylists().getUploads();
uploadPlaylistId 应该是我的频道 ID,但我不知道它是什么,我只知道这是一个空频道。 (如果我使用我的真实 ID 频道查看此处,我可以列出我的上传内容,似乎我的服务帐户在我的 YouTube 帐户上没有正确引用...)
【问题讨论】:
-
YouTube API 不支持您需要使用 Oauth2 的服务帐户
标签: java oauth-2.0 youtube-api youtube-data-api