gpt4 book ai didi

java - 我如何从java中的Youtube channel API v3获取所有上传的视频

转载 作者:太空宇宙 更新时间:2023-11-04 13:18:44 24 4
gpt4 key购买 nike

如何获取某个 channel 所有上传的视频?我知道 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();
}
}

我收到禁止 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."
}

最佳答案

该错误似乎具有完美的描述性。您没有验证您的请求,因此从 YouTube 的角度来看,您在未登录的情况下尝试过于频繁地调用此 API。

如果您使用有效 YouTube 帐户的真实凭据签署请求,应该没问题。

关于java - 我如何从java中的Youtube channel API v3获取所有上传的视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33306287/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com