如何从远程服务器访问Google云端硬盘应用数据?

问题描述:

对于我的应用程序,我希望用户能够在Google云端硬盘上存储文件,并希望我的服务能够访问使用该应用程序创建的相同文件.

For my application I want the user to be able to store files on Google Drive and for my service to have access to these same files created with the application.

我为Web应用程序创建了一个客户端ID,并且能够使用drive.appfolder范围从JavaScript(客户端)上载/列出/下载文件.很好,这是我要做的一半.

I created a Client ID for web application and was able to upload/list/download files from JavaScript (client side) with drive.appfolder scope. This is good, this is half of what I want to do.

现在,我想从Node.js(服务器端)访问相同的文件.我不知道该怎么做.是否为服务器创建新的客户端ID? (如果是,则用户将如何进行身份验证?)我是否通过了用户获得的AuthToken并尝试在服务器上使用它?我认为这不会起作用,因为AuthToke具有时间敏感性(并且可能不打算在多个IP中使用).

Now I want to access the same files from Node.js (server side). I am lost as to how to do this. Do I create a new Client ID for the server? (if so, how will the user authenticate?) Do I pass the AuthToken my user got client-side and try to use that on the server? I don't think this will work as the AuthToke is time-sensitive (and probably not intended to be used from multiple IPs).

任何方向或示例服务器端代码都将有所帮助.同样,我只想访问用户使用我的应用程序创建的相同文件,而不是用户Google云端硬盘中的其他文件.

Any direction or example server-side code will be helpful. Again, all I want is to access these same files the user created with my application, not any other files in the user's Google Drive.

澄清:我认为我的问题归结为:是否可以在客户端和服务器端访问Google云端硬盘上的相同应用程序数据?"

CLARIFICATION: I think my question boils down to: "Is it possible to access the same Application Data on Google Drive both client-side and server-side?"

是否为服务器创建新的客户端ID?

由您决定.您不需要,但是可以.见下文.

Up to you. You don't need to, but you can. See below.

如果是,用户将如何进行身份验证?

由您决定. OAuth是关于授权而不是身份验证的. 万一您要授权,用户可以授权该项目,该项目可能包含多个客户端ID.

Up to you. OAuth is about authorisation, not authentication. Just in case you meant authorisation, the user authorises the Project, which may contain multiple client IDs.

我是否将我的用户获得的AuthToken传递给客户端,并尝试在服务器上使用它?

您可以做到,但出于您陈述的理由,这不是一个好主意.首选方法是拥有一个单独的服务器客户端ID,并使用该ID来请求脱机访问,该脱机访问将(最终)返回一个刷新令牌,该令牌存储在服务器中.然后,您可以在需要时使用该刷新令牌来请求访问令牌.

You can do, but not a good idea for the reason you state. The preferred approach is to have a separate server Client ID, and use that to request offline access, which returns (eventually) a Refresh Token, which you store in your server. You then use that Refresh Token to request Access Tokens whenever you need them.

AuthToken是...(可能不打算在多个IP中使用).

绑定到特定IP地址

是否可以在客户端和服务器端访问Google云端硬盘上的相同应用程序数据?"

您最需要的是位于 https://developers.google.com/accounts/docs /OAuth2WebServer