我正在尝试使用方法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";
答案 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";