如何从特定频道获取所有上传的视频?
我知道GET请求是
https://www.googleapis.com/youtube/v3/search?key=key&channelId=UC-9-kyTW8ZkZNDHQJ6FgpwQ&part=snippet,id&order=date&maxResults=20
但我想使用Java Youtube APi(v3) 当我想要这样做时
try {
youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest arg0) throws IOException {}
}).setApplicationName("youtube-cmdline-myuploads-sample").build();
YouTube.Channels.List channelRequest = youtube.channels().list("contentDetails");
channelRequest.setId("UC-9-kyTW8ZkZNDHQJ6FgpwQ"); //youtube channel id
channelRequest.setKey(key);
channelRequest.setFields("items/contentDetails,nextPageToken,pageInfo");
ChannelListResponse channelResult = channelRequest.execute();
List<Channel> channelsList = channelResult.getItems();
if (channelsList != null) {
String uploadPlaylistId =
channelsList.get(0).getContentDetails().getRelatedPlaylists().getUploads();
System.out.println(uploadPlaylistId);
List<PlaylistItem> playlistItemList = new ArrayList<PlaylistItem>();
YouTube.PlaylistItems.List playlistItemRequest =
youtube.playlistItems().list("id,contentDetails,snippet");
playlistItemRequest.setPlaylistId(uploadPlaylistId);
playlistItemRequest.setFields(
"items(contentDetails/videoId,snippet/title,snippet/publishedAt),nextPageToken,pageInfo");
String nextToken = "";
do {
playlistItemRequest.setPageToken(nextToken);
PlaylistItemListResponse playlistItemResult = playlistItemRequest.execute();
playlistItemList.addAll(playlistItemResult.getItems());
nextToken = playlistItemResult.getNextPageToken();
} while (nextToken != null);
printVideos(playlistItemList.size(), playlistItemList.iterator());
}
} catch (GoogleJsonResponseException e) {
e.printStackTrace();
System.err.println("There was a service error: " + e.getDetails().getCode() + " : "
+ e.getDetails().getMessage());
} catch (Throwable t) {
t.printStackTrace();
}
}
我得到了forbidden 403
。我做错了什么?
"code" : 403,
"errors" : [ {
"domain" : "usageLimits",
"message" : "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
"reason" : "dailyLimitExceededUnreg",
"extendedHelp" : "https://code.google.com/apis/console"
} ],
"message" : "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
}
答案 0 :(得分:0)
该错误似乎完全具有描述性。您没有对您的请求进行身份验证,因此从Youtube的角度来看,您尝试在未登录时过于频繁地调用此API。
如果您使用有效的Youtube帐户的真实凭据签署您的请求,那么您应该没问题。