gpt4 book ai didi

java - 使用 gmail api 和 android 客户端获取完整的电子邮件正文内容

转载 作者:太空宇宙 更新时间:2023-11-04 11:48:25 25 4
gpt4 key购买 nike

我需要使用 Android 客户端和 gmail api 获取完整的电子邮件正文内容。以下是我用来获取电子邮件内容的 Android 代码

     String user = "me";
List<String> messages=new ArrayList<>();
ListMessagesResponse listresponse=mService.users().messages().list(user).execute();

int a=0;
for(Message message:listresponse.getMessages()){
messages.add(message.getId());
a++;
}

for(int i=0;i<=a;i++){
Message message=mService.users().messages().get(user, messages.get(i)).setFormat("raw").execute();

try {

Log.d("Body", String.valueOf(message));

}
catch (Throwable t){
Log.e("My app", "not done");
}
}

return messages;

}

然后我收到以下输出。

     D/Body: {"historyId":"******","id":"************","internalDate":"************","labelIds":["CATEGORY_PROMOTIONS","UNREAD","INBOX"],"raw":"RGVsaXZlcmVkLVRvOiBqYW5pdGhhMjAwQGdtYWlsLmNvbQ0KUmVjZWl2ZWQ6IGJ5IDEwLjE5NC4yMjguNzEgd2l0aCBTTVRQIGlkIHNnN2NzcDE4MTkwMzd3amM7DQogICAgICAgIE1vbiwgNiBGZWIgMjAxNyAxMDoyMzozMCAtMDgwMCAoUFNUKQ0KWC1SZWNlaXZlZDogYnkgMTAuODQuMjMyLjIwMSB3aXRoIFNNVFAgaWQgeDltcjE5MzY2MDAycGxtLjEwMi4xNDg2NDA1NDA5OTkyOw0KICAgICAgICBNb24sIDA2IEZlYiAyMDE3IDEwOjIzOjI5IC0wODAwIChQU1QpDQpSZXR1cm4tUGF0aDogPHVkZW15QGVtYWlsLnVkZW15LmNvbT4NClJlY2VpdmVkOiBmcm9tIG9tcC5lbWFpbC51ZGVteS5jb20gKG9tcC5lbWFpbC51ZGVteS5jb20uIFsxOTkuNy4yMDIuMjQ0XSkNCiAgICAgICAgYnkgbXguZ29vZ2xlLmNvbSB3aXRoIEVTTVRQUyBpZCBwODNzaTE0MzA5NzNwZmouMzUuMjAxNy4wMi4wNi4xMC4yMy4yOQ0KICA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PXRydWUmX3JpXz1YMEd6YzJYJTNEWVFwZ2xMakhKbFlRR283STRpcHpmNzIyemV6YmUzMHpncllqY1hjOWFzdXc2YW96Y

我在解码此输出中的正文内容时遇到问题。那么我必须遵循什么机制才能获得完整的正文内容?谢谢。

最佳答案

这有效

String user = "me";
List<String> messageList = new ArrayList<>();
String query = "in:inbox";
ListMessagesResponse messageResponse =
mService.users().messages().list(user).setQ(query).setMaxResults(Long.valueOf(6)).execute();

List<Message> messages = messageResponse.getMessages();

for (Message message : messages) {
Message message2 = mService.users().messages().get(user, message.getId()).execute();

//Get Body
byte[] bodyBytes = Base64.decodeBase64(message2.getPayload().getParts().get(0).getBody().getData().trim().toString()); // get body
String body = new String(bodyBytes, "UTF-8");

messageList.add(body);
Log.d("bb", body);
}

关于java - 使用 gmail api 和 android 客户端获取完整的电子邮件正文内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42080586/

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