2014-05-23 47 views
0

我遇到的問題而訪問目錄API來獲取用戶數據:問題,同時通過目錄谷歌API蒲凌用戶信息

com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden 
{ 
    "code" : 403, 
    "errors" : [ { 
    "domain" : "usageLimits", 
    "message" : "Access Not Configured. Please use Google Developers Console to activate the API for your project.", 
    "reason" : "accessNotConfigured" 
    } ], 
    "message" : "Access Not Configured. Please use Google Developers Console to activate the API for your project." 
}. 

我用來訪問它的代碼:

Directory service = (Directory) GoogleClientHelper.getClientOAuth20(Directory.Builder.class, email, null, null); 
    Directory.Users.Get request = service.users().get(email); 
    User user = request.execute(); 

然而,以下代碼完美:

 Directory service = (Directory) GoogleClientHelper.getClientOAuth20(Directory.Builder.class, email, null, null); 
     Directory.Users.List request = service.users().list().setCustomer(adminAccount); 

     do { 
      try { 
       Users currentPage = request.execute(); 
       allUsers.addAll(currentPage.getUsers()); 
       request.setPageToken(currentPage.getNextPageToken()); 
      } catch (IOException e) { 
       System.out.println("An error occurred: " + e); 
       request.setPageToken(null); 
      } 
     } while (request.getPageToken() != null && request.getPageToken().length() > 0); 

請支持。

謝謝 葉夫根尼·

回答

1

從錯誤中,它看起來像在開發者控制檯的API項目配置不正確(可能有管理員SDK設置爲「OFF」)。查看'設置您的API'下的here獲取更多信息。

當你說下面的代碼完美工作時,它是否使用另一個API項目?

+1

它工作。謝謝。 – EVG