我通过将此照片发送到bot,使用此代码并从机器人响应中复制file_id来获取照片的file_id:
if(receivedUpdate != null && receivedUpdate.getMessage().hasPhoto())
{
String file_id_avoid = receivedUpdate.getMessage().getPhoto().stream().findFirst().orElse(null).getFileId();
sendMessage_text(file_id_avoid);
}
然后我正在使用它:
messageToBeSent_PHOTO.setPhoto("AgADAgADCagxG29QQEpt1IJFo-l3xVToDw4ABAopYoYfhAlE7P0AAgI").setCaption(null);
sendMessage_photo();
它说:
org.telegram.telegrambots.exceptions.TelegramApiValidationException:照片在方法中不能为空:SendPhoto {chatId =' 230164432',photo =' null',caption = ' null',replyToMessageId = null,replyMarkup = null,isNewPhoto = false}