集成 Java Servlets 中的 Google Sheets API

huangapple go评论76阅读模式
英文:

Integrating Google Sheets API in Java Servlets

问题

如何实现这个?

我正在按照[这个谷歌文档][1]进行操作。

目前,我的SheetsQuickstart.java文件运行时出现以下错误:

	at com.google.api.client.http.javanet.NetHttpTransport$Builder.build(NetHttpTransport.java:317)
	at com.google.api.client.googleapis.javanet.GoogleNetHttpTransport.newTrustedTransport(GoogleNetHttpTransport.java:55)
	at SheetsQuickstart.main(SheetsQuickstart.java:63)```
我应该把```credentials.json```文件放在哪里?

在servlet中还有没有其他步骤可以解决这个问题?是否有文档或简单的示例项目(或任何相关内容)可以帮助解决?

  [1]: https://developers.google.com/sheets/api/quickstart/java

<details>
<summary>英文:</summary>

HOW CAN I ACHIEVE THIS?

I am following [this google doc.][1]

Currently, my ```SheetsQuickstart.java``` file runs with the following error:

Exception in thread "main" java.lang.NoSuchMethodError: com.google.api.client.http.javanet.NetHttpTransport.<init>(Lcom/google/api/client/http/javanet/ConnectionFactory;Ljavax/net/ssl/SSLSocketFactory;Ljavax/net/ssl/HostnameVerifier;)V
at com.google.api.client.http.javanet.NetHttpTransport$Builder.build(NetHttpTransport.java:317)
at com.google.api.client.googleapis.javanet.GoogleNetHttpTransport.newTrustedTransport(GoogleNetHttpTransport.java:55)
at SheetsQuickstart.main(SheetsQuickstart.java:63)

Where should I keep my ```credentials.json``` file?

Are there any more steps in servlets to overcome this? Any Doc or a simple demo project(or anything related) will help 


  [1]: https://developers.google.com/sheets/api/quickstart/java

</details>


# 答案1
**得分**: 0

我的问题基本上是:

&gt; 在使用Java Struts或Servlets时,应该把credentials.json文件放在哪里?

所提到的链接(Google文档)描述了Android的配置(我认为是这样)。
在尝试后,我发现您可以将```credentials.json```文件放在您的```src```文件夹中。

另外,使用GAPI的步骤如下:
 1. 在Google控制台中创建一个项目。
 2. 配置您的OAuth屏幕。
 3. 创建您的OAuth凭据。
 4. 下载```credentials.json```并将其放置在您的src文件夹中。
就是这样。希望能对某人有所帮助。

<details>
<summary>英文:</summary>

My Question basically was:

&gt; Where to keep the credentials.json files if you are working with Java struts or servlets?

The mentioned link (Google Doc) describes the config for android (I think).
After experimenting with it, I found that you can keep the ```credentials.json``` in your ```src``` folder itself. 

Also, the steps to use GAPI are: 
 1. Create a project in Google Console.
 2. Config your OAuth Screen.
 3. Create your OAuth Credentials.
 4. Download ```credentials.json``` and place it your src folder.
That should be it. Hope it helps somebody.

</details>



huangapple
  • 本文由 发表于 2020年8月26日 22:23:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/63599752.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定