Gmail API会返回403错误代码和使用限制错误

时间:2015-03-02 15:44:36

标签: android api gmail

我正在尝试将gmail API添加到我的应用程序中,但是我收到此错误:

03-02 15:30:23.555: W/System.err(7765): com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
03-02 15:30:23.555: W/System.err(7765): {
03-02 15:30:23.555: W/System.err(7765):   "code" : 403,
03-02 15:30:23.555: W/System.err(7765):   "errors" : [ {
03-02 15:30:23.555: W/System.err(7765):     "domain" : "usageLimits",
03-02 15:30:23.555: W/System.err(7765):     "message" : "Access Not Configured. The API (Gmail API) is not enabled for your project. Please use the Google Developers Console to update your configuration.",
03-02 15:30:23.555: W/System.err(7765):     "reason" : "accessNotConfigured",
03-02 15:30:23.555: W/System.err(7765):     "extendedHelp" : "https://console.developers.google.com"
03-02 15:30:23.555: W/System.err(7765):   } ],
03-02 15:30:23.556: W/System.err(7765):   "message" : "Access Not Configured. The API (Gmail API) is not enabled for your project. Please use the Google Developers Console to update your configuration."
03-02 15:30:23.556: W/System.err(7765): }
03-02 15:30:23.557: W/System.err(7765):     at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)

这是我的Gmail API类:

public class GmailAPI { 
    private Context context;
    private final String SCOPE = "https://www.googleapis.com/auth/gmail.readonly";
    private final String APP_NAME = "Gmail API Quickstart";

    public GmailAPI(Context context,String token,String user) throws IOException {
        this.context = context;

        HttpTransport httpTransport = new NetHttpTransport();
        JsonFactory jsonFactory = new JacksonFactory();

        GoogleCredential credential = new GoogleCredential().setAccessToken(token);

        Gmail service = new Gmail.Builder(httpTransport, jsonFactory, credential).setApplicationName(APP_NAME).build();

        ListThreadsResponse threadsResponse = service.users().threads().list("me").execute();
        List<Thread> threads = threadsResponse.getThreads();

        for (Thread thread : threads) {
            Log.d(">>> Threads","Thread ID: " + thread.getId());
        }
    }
}

在开发者控制台中,我使用我的应用程序的软件包名称和sha1创建了一个新的客户端ID,并且我还启用了Gmail API,Google + API,Contacts API。

0 个答案:

没有答案