Android アプリケーションを使用して Gmail API にアクセスしようとしています。利用可能なすべてのスコープの組み合わせを使用して、アクセス トークンを正常に要求し、受け取りました。しかし、実際に Gmail API コマンドを使用しようとするたびに、403 exception reading: Access not configured please use Google developers console to activate the api...
言うまでもなく、API が有効になり、正しいパッケージ名と sha1 コードを使用してクライアント キーが作成されました。同じクライアント ID は、Google Plus 機能でうまく機能します。
この問題を抱えている人、または Android から Gmail API への接続に成功した人はいますか?
ありがとう
ログは次のとおりです。
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): }
Google+ API と Gmail API 以外に API コンソールで有効にする必要がある API はありますか?
編集:
WebView ベースの認証を使用すると、Gmail API アクセスを許可するアクセス トークンが生成されることがわかりましたが、トークンの有効期間が短いため、これは有効なソリューションではありません。今のところ、GoogleAuthUtil はトークンを付与しますが、その権限は Gmail API を使用するのに十分ではありません。Android と Gmail API の接続に成功した人はいますか?共有したいと思いますか?
EDIT2:
ここに私がやっていることのスニペットがあります:
トークンの取得:
token = GoogleAuthUtil.getToken(MainActivity.this, Plus.AccountApi.getAccountName(mGoogleApiClient), scope);
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 サービスを使用すると、例外がキャッチされます。さらに、トークンをクリアして、同じ結果で新しいトークンを要求しようとしました。