我正在尝试使用Gmail API来阻止客户端发送邮件。我从开发者网站上获取了发送邮件代码。
https://developers.google.com/gmail/api/SendEmail.java
我相信我已经包含了执行此过程所需的所有库。
我在这个方法中遇到错误:
public static Message sendMessage(Gmail service,
String userId,
MimeMessage emailContent)
throws MessagingException, IOException {
Message message = createMessageWithEmail(emailContent);
message = service.users().messages().send(userId, message).execute();
System.out.println("Message id: " + message.getId());
System.out.println(message.toPrettyString());
return message;
}
错误地发生在这一行:
message = service.users().messages().send(userId, message).execute();
我无法弄清楚这里有什么问题。我尝试了stackoverflow中的其他问题,但似乎仍有一个浮动的问题与相同的主题没有答案很长一段时间。
send mail using gmail api in android
10-26 00:56:45.598 30338-30753/com.mail.dinesh.mailapplication W/System.err: com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException
10-26 00:56:45.598 30338-30753/com.mail.dinesh.mailapplication W/System.err: at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential$RequestHandler.intercept(GoogleAccountCredential.java:299)
10-26 00:56:45.598 30338-30753/com.mail.dinesh.mailapplication W/System.err: at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:868)
10-26 00:56:45.598 30338-30753/com.mail.dinesh.mailapplication W/System.err: at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
10-26 00:56:45.598 30338-30753/com.mail.dinesh.mailapplication W/System.err: at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
10-26 00:56:45.598 30338-30753/com.mail.dinesh.mailapplication W/System.err: at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
10-26 00:56:45.598 30338-30753/com.mail.dinesh.mailapplication W/System.err: at com.mail.dinesh.mailapplication.googleUtils.SendEmail.sendMessage(SendEmail.java:78)
10-26 00:56:45.598 30338-30753/com.mail.dinesh.mailapplication W/System.err: at com.mail.dinesh.mailapplication.googleUtils.GmailHelper.sendMail(GmailHelper.java:126)
10-26 00:56:45.598 30338-30753/com.mail.dinesh.mailapplication W/System.err: at com.mail.dinesh.mailapplication.SendMailActivity$MakeRequestTask.doInBackground(SendMailActivity.java:397)
10-26 00:56:45.598 30338-30753/com.mail.dinesh.mailapplication W/System.err: at com.mail.dinesh.mailapplication.SendMailActivity$MakeRequestTask.doInBackground(SendMailActivity.java:359)
10-26 00:56:45.599 30338-30753/com.mail.dinesh.mailapplication W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:295)
10-26 00:56:45.599 30338-30753/com.mail.dinesh.mailapplication W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
10-26 00:56:45.599 30338-30753/com.mail.dinesh.mailapplication W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
10-26 00:56:45.599 30338-30753/com.mail.dinesh.mailapplication W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
10-26 00:56:45.599 30338-30753/com.mail.dinesh.mailapplication W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
10-26 00:56:45.599 30338-30753/com.mail.dinesh.mailapplication W/System.err: at java.lang.Thread.run(Thread.java:818)
10-26 00:56:45.599 30338-30753/com.mail.dinesh.mailapplication W/System.err: Caused by: com.google.android.gms.auth.UserRecoverableAuthException: NeedPermission
10-26 00:56:45.599 30338-30753/com.mail.dinesh.mailapplication W/System.err: at com.google.android.gms.auth.zzd$1.zzar(Unknown Source)
10-26 00:56:45.599 30338-30753/com.mail.dinesh.mailapplication W/System.err: at com.google.android.gms.auth.zzd$1.zzas(Unknown Source)
10-26 00:56:45.599 30338-30753/com.mail.dinesh.mailapplication W/System.err: at com.google.android.gms.auth.zzd.zza(Unknown Source)
10-26 00:56:45.599 30338-30753/com.mail.dinesh.mailapplication W/System.err: at com.google.android.gms.auth.zzd.zzc(Unknown Source)
10-26 00:56:45.599 30338-30753/com.mail.dinesh.mailapplication W/System.err: at com.google.android.gms.auth.zzd.getToken(Unknown Source)
10-26 00:56:45.599 30338-30753/com.mail.dinesh.mailapplication W/System.err: at com.google.android.gms.auth.zzd.getToken(Unknown Source)
10-26 00:56:45.599 30338-30753/com.mail.dinesh.mailapplication W/System.err: at com.google.android.gms.auth.zzd.getToken(Unknown Source)
10-26 00:56:45.599 30338-30753/com.mail.dinesh.mailapplication W/System.err: at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
10-26 00:56:45.600 30338-30753/com.mail.dinesh.mailapplication W/System.err: at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.getToken(GoogleAccountCredential.java:269)
10-26 00:56:45.615 30338-30753/com.mail.dinesh.mailapplication W/System.err: at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential$RequestHandler.intercept(GoogleAccountCredential.java:294)
10-26 00:56:45.616 30338-30753/com.mail.dinesh.mailapplication W/System.err: ... 14 more
Android Drive API: getting Sys.err UserRecoverableAuthIOException if i merge code to other projects 解决了一些问题。错误更改为400错误请求。