采用Android的Gmail API访问 [英] Gmail API access using Android

查看:257
本文介绍了采用Android的Gmail API访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图访​​问使用Android应用程序的Gmail的API。 我已经成功申请并获得使用所有可用的范围内组合的访问令牌。 但似乎每一次我竟然尝试使用Gmail的API命令我得到一个 403例外阅读:访问未配置,请使用谷歌开发者控制台来激活API ...

I am trying to access the Gmail API using an Android application. I have successfully requested and received an access token using all available scope combinations. But it seems that every time I actually try to use the Gmail API command I am getting a 403 exception reading: Access not configured please use Google developers console to activate the api...

不用说了API被激活和客户端密钥使用了正确的包名和放大器产生; SHA1 code。同一个客户端ID可以很好地处理谷歌加功能。

Needless to say the API is activated and a client key was created using the correct package name & sha1 code. Same client ID works well with Google Plus features.

有任何人这个问题,或成功地连接到从Android的Gmail的API?

Anyone having this issue or succeeded in connecting to the Gmail api from Android?

感谢

下面是日志:

09-04 21:40:54.014: W/System.err(26717): com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
09-04 21:40:54.014: W/System.err(26717): {
09-04 21:40:54.014: W/System.err(26717):   "code" : 403,
09-04 21:40:54.014: W/System.err(26717):   "errors" : [ {
09-04 21:40:54.014: W/System.err(26717):     "domain" : "usageLimits",
09-04 21:40:54.014: W/System.err(26717):     "message" : "Access Not Configured. Please use Google Developers Console to activate the API for your project.",
09-04 21:40:54.014: W/System.err(26717):     "reason" : "accessNotConfigured"
09-04 21:40:54.014: W/System.err(26717):   } ],
09-04 21:40:54.014: W/System.err(26717):   "message" : "Access Not Configured. Please use Google Developers Console to activate the API for your project."
09-04 21:40:54.014: W/System.err(26717): }

是否有需要在API控制台中启用除Google+的API和Gmail API任何其他API的?

Are there any other API's that need to be enabled in the API Console except Google+ API and Gmail API?

编辑:

我们发现,使用web视图基础的认证,将导致,将授予的Gmail API访问的访问令牌但这并不是一个有效的解决方案,因为令牌被短暂的。至于现在的GoogleAuthUtil将授予一个令牌,但它的权限不足以使用Gmail的API。 没有人有成功与Gmail的API连接Android和想与大家分享?

I have found out that using a WebView based authentication will result in an access token that will grant Gmail API access but this is not a valid solution because the token is short lived. As for now the GoogleAuthUtil will grant a token but it's privileges are not sufficient for using the Gmail API. anyone had success in connecting Android with the Gmail API and would like to share?

EDIT2:

下面是我在做什么片段:

Here are snippets of what I am doing:

获取令牌:

token = GoogleAuthUtil.getToken(MainActivity.this, Plus.AccountApi.getAccountName(mGoogleApiClient), scope);

尝试获取来自Gmail的API消息:

Trying to fetch messages from the Gmail API:

GoogleCredential credential = new GoogleCredential().setAccessToken(token);
JsonFactory jsonFactory = new JacksonFactory();
HttpTransport httpTransport = new NetHttpTransport();

service = new Gmail.Builder(httpTransport, jsonFactory, credential).setApplicationName("GmailApiTP").build();
ListMessagesResponse messagesRespose;
List<Message> m = null;

ArrayList<String> ids = new ArrayList<String>();
ids.add("INBOX");
try {
    messagesRespose = service.users().messages().list("me").setLabelIds(ids).setQ("From: something")
            .execute();
    m = messagesRespose.getMessages();

} catch (IOException e) {
    e.printStackTrace();
}

在使用Gmail的API服务将抛出异常。另外我试图清除令牌并要求一个新的使用相同的结果。

The exception is caught when use the Gmail API service. In addition I have tried clearing the token and asking for a new one with the same result.

推荐答案

该错误信息是骗人的,我相信它也发生在开发项目的凭据客户端是不正确的。例如您选择Web应用程序,当你真正想要的安装应用程序。

That error message is deceptive, I believe it also happens when the developer project credentials client isn't correct. For example you picked "web application" when really you want "installed application".

确认你正确地从如下的说明: https://developers.google.com/accounts/docs/OAuth2

Confirm you're correctly following instructions from: https://developers.google.com/accounts/docs/OAuth2

(应该是安装应用程序,等等。)

(Should be "installed application", etc.)

你能发布的OAuth客户端信息,你必须从开发商控制台? (类型,并在那里任何其他非机密信息,等等。)

Can you post the oauth client info you have from the developers console? (Type and any other non-confidential info in there, etc.)

这篇关于采用Android的Gmail API访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆