First I apologize if I'm a dolt and am missing something obvious, but I've spent a few hours scouring documentation and am lost.

I'm trying to write a python script that will upload a bunch of images to a single user's Google Drive. The user already exists and will never change. I am not writing a web app and don't plan to use any user interface whatsoever. Everything will be done through code.

As best I can understand from the Google documentation, I have two choices:

1) Write a web app and register it to use the Drive DSK. This of course requires having urls and such for the web app.

2) Create a service account, which ties my "app" to a new service account email.

Neither of these options works for me. Is there any way to simply log in to a single user account and access their drive through python scripting?

有帮助吗?

解决方案

There is a deprecated API called ClientLogin that would enable you to use the username and password for a login to access that Drive data.

But the basic idea is that you should be using something more secure -- from your users' point of view -- that allows them to authorize you without giving you their password.

For your use case it is possible that the user is you or someone you know and that you are accessing their account through a more personal kind of authorization. In that case, ClientLogin may be your best choice. If this is an application designed to be used by arbitrary users, the deprecation of ClientLogin is for a good reason and I would urge you to bite the bullet and choose one of the supported options.

其他提示

The correct solution is to separate the authorization phase from the access phase. The authorization process needs to be run one time only, and can be done from a simple web site. The result of this is a refresh token which is analogous to a username/password. You will need to be aware of the security implications. Make sure you only grant drive.file scope to minimise the impact of a security breach.

Since you are uploading images, you might also want to look at the picassa api.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top