使用Java的Google驱动器API客户端库进行身份验证以上传驱动器中的文件 [英] Authentication to upload files in my drive using Google drive API client library for Java

本文介绍了使用Java的Google驱动器API客户端库进行身份验证以上传驱动器中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有基于Spring + Maven的Java应用程序,具有其余的Web服务. 对于此其余网络服务的每次调用,我都希望我的应用程序将文件上传到我的Google驱动器帐户.

I have spring+maven based java application having rest web service. For each call to this rest webservice, I want my application to upload a file to my google drive account.

我发现了.

在上传应用程序之前,如何认证帐户?我是否需要用于Web应用程序服务器应用程序的Google OAuth2.0 ?或 Java快速入门指南中的身份验证方法将对我的应用程序有效?我是OAuth的新手.

How can I authentication account before uploading in my application? Do I need Google OAuth2.0 for web application server application? or Authentication method in quick start guide for java will do for my application? I am new to OAuth.

关于Google驱动器身份验证和使用驱动器API是否有完整的指南?

Is there any complete guide on google drive authentication and using drive APIs?

已安装应用程序的google Oauth2.0和用于Web应用程序服务器的google Oauth2.0有什么区别?我应该何时使用它们?

What is the difference between google Oauth2.0 for installed app and google Oauth2.0 for web application server? When should I use each?

推荐答案

如果您已在快速入门中使用了Authentication方法,那么将需要经过身份验证的上传文件请求.

If you've used the Authentication method in the Quickstart, that will do to have a authenticated request for uploading files.

在快速入门中对服务器应用程序和身份验证方法进行一些描述:

To give a little description about Server Application and Authentication method in the Quickstarts:

服务器应用程序身份验证 大多与<使用href ="https://developers.google.com/identity/protocols/OAuth2ServiceAccount" rel ="nofollow noreferrer">服务帐户来授权API请求,尤其是在调用Cloud API来访问基于项目的数据时而不是特定于用户的数据. Web服务器应用程序可以将服务帐户与用户授权一起使用.

Server Application Authentication are mostly paired with service accounts to authorize API requests, particularly when calling Cloud APIs to access project-based data rather than user-specific data. Web server applications can use service accounts in conjunction with user authorization.

此OAuth 2.0流专门用于用户授权.它是为可以存储机密信息并维护状态的应用程序而设计的.在用户与该应用程序交互时或在用户离开该应用程序之后,经过适当授权的Web服务器应用程序可以访问API.

This OAuth 2.0 flow is specifically for user authorization. It is designed for applications that can store confidential information and maintain state. A properly authorized web server application can access an API while the user interacts with the application or after the user has left the application.

已安装应用的OAuth 2.0

一些像Javascript(客户端)这样的OAuth 2.0身份验证称为隐式授予流.它是为仅在用户出现在应用程序中时才访问API的应用程序而设计的.这些应用程序无法存储机密信息.

While some OAuth 2.0 Authentication like Javascript (Client-Side) is called the implicit grant flow. It is designed for applications that access APIs only while the user is present at the application. These applications are not able to store confidential information.

在此流程中,您的应用程序打开一个Google URL,该URL使用查询参数来识别您的应用程序以及该应用程序所需的API访问类型.您可以在当前浏览器窗口或弹出窗口中打开URL.用户可以向Google进行身份验证并授予所请求的权限.然后,Google将用户重定向回您的应用.重定向包含一个访问令牌,您的应用程序将对其进行验证,然后将其用于发出API请求.

In this flow, your app opens a Google URL that uses query parameters to identify your app and the type of API access that the app requires. You can open the URL in the current browser window or a popup. The user can authenticate with Google and grant the requested permissions. Google then redirects the user back to your app. The redirect includes an access token, which your app verifies and then uses to make API requests.

希望这会有所帮助.

这篇关于使用Java的Google驱动器API客户端库进行身份验证以上传驱动器中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆