带有Oauth和服务帐户的GData

时间:2022-03-16 15:18:31

I am in a strange problem. I am writing an application in core java which needs to access its own account at google docs. So after doing a lot of googling, I found that OAuth2.0 with Service Account is something I am looking for. But I am not using App Engine or anything. Its a simple application. I don't know how can I use the OAuth. I have written below code and I dont know how to proceed further. Looking for someone to guide me further:

我有一个奇怪的问题。我正在核心java中编写一个应用程序,需要在google docs*问自己的帐户。所以经过大量的谷歌搜索,我发现OAuth2.0与服务帐户是我正在寻找的东西。但我没有使用App Engine或其他任何东西。它的应用很简单。我不知道如何使用OAuth。我写了下面的代码,我不知道如何进一步。寻找有人进一步指导我:

GoogleCredential credential = new GoogleCredential.Builder().setTransport(HTTP_TRANSPORT).setJsonFactory(JSON_FACTORY)
                                                                    .setServiceAccountId(EMAIL)
                                                                    .setServiceAccountScopes(SCOPE)
                                                                    .setServiceAccountPrivateKeyFromP12File(new File("lib/key.p12")).build();

SpreadsheetService service = new SpreadsheetService("My test Service");
             //service .setOAuthCredentials(parameters, signer);

Thanks you !

谢谢 !

1 个解决方案

#1


0  

From the Google Documents List API version 3.0 page, it seems that the Google Docs API is now deprecated, and you should instead use the Google Drive API. It also uses OAuth2, and thus also supports service accounts. For a quick start tutorial on connecting to Google Drive and creating a new file, see Quickstart: Run a Drive App in Java. For more Java specific OAuth2 information, see the google-api-java-client page, and in particular the Service Accounts section of that page.

在Google文档列表API 3.0版页面中,似乎已弃用Google文档API,您应该使用Google Drive API。它还使用OAuth2,因此也支持服务帐户。有关连接到Google云端硬盘和创建新文件的快速入门教程,请参阅快速入门:使用Java运行云端硬盘应用。有关更具体的Java特定OAuth2信息,请参阅google-api-java-client页面,特别是该页面的“服务帐户”部分。

#1


0  

From the Google Documents List API version 3.0 page, it seems that the Google Docs API is now deprecated, and you should instead use the Google Drive API. It also uses OAuth2, and thus also supports service accounts. For a quick start tutorial on connecting to Google Drive and creating a new file, see Quickstart: Run a Drive App in Java. For more Java specific OAuth2 information, see the google-api-java-client page, and in particular the Service Accounts section of that page.

在Google文档列表API 3.0版页面中,似乎已弃用Google文档API,您应该使用Google Drive API。它还使用OAuth2,因此也支持服务帐户。有关连接到Google云端硬盘和创建新文件的快速入门教程,请参阅快速入门:使用Java运行云端硬盘应用。有关更具体的Java特定OAuth2信息,请参阅google-api-java-client页面,特别是该页面的“服务帐户”部分。