返回null的LiveChatMessage上的getId() - YT Data API v3

时间:2017-12-09 03:39:24

标签: java youtube-data-api

我正在尝试使用方法getId()获取LiveChatMessage的ID。它出于某种原因返回null。有人可以帮帮我吗?

以下是我的代码的一部分。

LiveChatMessageListResponse response = youtube
                            .liveChatMessages()
                            .list(liveChatId, "snippet, authorDetails")
                            .setPageToken(nextPageToken)
                            .setFields(LIVE_CHAT_FIELDS)
                            .execute();

List<LiveChatMessage> messages = response.getItems();
for (int i = 0; i < messages.size(); i++) {
    LiveChatMessage message = messages.get(i);
    final String[] full = new String[2];
    System.out.println("ID: " + message.getId());

以下是我的LIVE_CHAT_FIELDS

private static final String LIVE_CHAT_FIELDS =
    "items(authorDetails(channelId,displayName,isChatModerator,isChatOwner,isChatSponsor,"
        + "profileImageUrl),snippet(displayMessage,superChatDetails,publishedAt)),"
        + "nextPageToken,pollingIntervalMillis";

1 个答案:

答案 0 :(得分:0)

您的LIVE_CHAT_FIELDS不包含该ID。

items(中包含ID:

private static final String LIVE_CHAT_FIELDS =
    "items(id,authorDetails(channelId,displayName,isChatModerator,isChatOwner,isChatSponsor,"
        + "profileImageUrl),snippet(displayMessage,superChatDetails,publishedAt)),"
        + "nextPageToken,pollingIntervalMillis";