我尝试使用Eclipse https://developers.google.com/sheets/api/quickstart/java
启动和
private static Credential authorize() throws Exception {
// load client secrets
GoogleClientSecrets clientSecrets =
GoogleClientSecrets.load(JSON_FACTORY,new
InputStreamReader(PlusSample.class.
getResourceAsStream("/client_secrets.json")));
给了我
*янв 22, 2018 12:47:46 AM com.google.api.client.util.store.FileDataStoreFactory setPermissionsToOwnerOnly
WARNING: unable to change permissions for everybody: C:\Users\805268\workspace\DoubleTimeSwing
янв 22, 2018 12:47:46 AM com.google.api.client.util.store.FileDataStoreFactory setPermissionsToOwnerOnly
WARNING: unable to change permissions for owner: C:\Users\805268\workspace\DoubleTimeSwing
java.lang.NullPointerException
at java.io.Reader.<init>(Unknown Source)
at java.io.InputStreamReader.<init>(Unknown Source)
at SandCourt.main33.PlusSample.authorize(PlusSample.java:72)
at SandCourt.main33.PlusSample.main(PlusSample.java:97)*
我使用过这种解决方式https://stackoverflow.com/a/34797777/9248765
并且遇到更多麻烦:
янв 22, 2018 1:47:09 PM com.google.api.client.util.store.FileDataStoreFactory setPermissionsToOwnerOnly
WARNING: unable to change permissions for everybody: C:\Users\805268\.credentials\sheets.googleapis.com-java-quickstart
янв 22, 2018 1:47:09 PM com.google.api.client.util.store.FileDataStoreFactory setPermissionsToOwnerOnly
WARNING: unable to change permissions for owner: C:\Users\805268\.credentials\sheets.googleapis.com-java-quickstart
Exception in thread "main" java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletRequest
at com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver.getRedirectUri(LocalServerReceiver.java:118)
at com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp.authorize(AuthorizationCodeInstalledApp.java:78)
at SandCourt.main33.Quickstart.authorize(Quickstart.java:74)
...
就行了 [78] flow,new LocalServerReceiver())。authorize(&#34; user&#34;);
我做错了什么?
答案 0 :(得分:0)
我有(JRE)而不是Java Development Kit(JDK),这是第2个问题。并且#1错了.Json文件。请仔细并严格按照步骤1的说明进行操作。https://developers.google.com/sheets/api/quickstart/java#step_1_turn_on_the_api_name