[英]How to set up a Google Drive Client ID for access without a local server?
I'm wondering if it's possible to, say, open up a jsfiddle on a random computer and log in and authenticate and use the drive API, without having to have a local server running all the time? 我想知道是否有可能在随机计算机上打开jsfiddle并登录并进行身份验证并使用驱动器API,而不必一直运行本地服务器? And how exactly does one go about setting this up?
究竟该如何设置呢? I'm sorry if this is a simple question but I'm just sorta lost because the instructions that I've found so far are unclear.
如果这是一个简单的问题,很抱歉,但是我有点迷失了,因为到目前为止我发现的说明尚不清楚。
Edit: 编辑:
So far I have, following from here and here : 到目前为止,我已经从这里和这里跟随:
I also have made a python application, to use pydrive I: 我还制作了一个python应用程序,以使用pydrive I:
However, beyond this, I'm a little unsure about, specifically: 但是,除此之外,我不确定:
I know that I most likely need to set up a Public API access in the developers console, but am not entirely sure what Referers I should use as well. 我知道我很可能需要在开发人员控制台中设置“公共API”访问权限,但不确定是否也应使用哪些引荐来源网址。 So is there a simple way to do any of this?
那么有没有简单的方法可以做到这一点?
I also know that gspread can open google excell spreadsheets only using the client's username and password, so I'm suspecting that what I'm looking for is possible, but I'm not sure. 我也知道gspread只能使用客户端的用户名和密码来打开google excell电子表格,因此我怀疑我在寻找什么是可能的,但是我不确定。
Okay, so I found a solution that works pretty well: 好的,所以我找到了一个很好用的解决方案:
{ "access_token": "ya29.AwH-1N_gnstLBuZfOR4W9CCcggKrQpMyKYV4QVEtCiIzHozNU5AfUJoYQzukALfjdiw2iOCUve7JbQ", "token_type": "Bearer", "expires_in": 3600, "provider": "google_drive" }
To use this, you can do something like: 要使用此功能,您可以执行以下操作:
// This only works because we're set to "No wrap - in <head>"
function ShowDriveFileList() {
var accessToken;
// Initialize OAuth with our key
OAuth.initialize('lmGlb8BaftfF4Y5en_c8XYOSq2A');
// Connect to google drive, and print out file list
OAuth.popup('google_drive').done(function (result) {
var xmlHttp = null;
xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", "https://www.googleapis.com/drive/v2/files", false);
xmlHttp.setRequestHeader("Authorization", "Bearer " + result.access_token);
xmlHttp.send(null);
alert(xmlHttp.responseText);
}).fail(function (err) {
alert(err);
});;
}
Which you can find at http://jsfiddle.net/JMTVz/41/ . 您可以在http://jsfiddle.net/JMTVz/41/中找到。 This uses my oauth.io client id, but you can replace it with yours and it should work as well.
这使用了我的oauth.io客户端ID,但是您可以将其替换为您的ID,并且它也应该可以正常工作。
You can do the same thing using the OAuth Playground. 您可以使用OAuth Playground做同样的事情。
See How do I authorise an app (web or installed) without user intervention? 请参阅如何在没有用户干预的情况下授权应用程序(网络或已安装)? (canonical ?)
(规范?)
Step 11 will be different. 步骤11将有所不同。 Instead of pasting the refresh token into your server app (which you don't have), you'll paste the access token into your JS in the same way as you are doing in your answer.
无需将刷新令牌粘贴到您的服务器应用程序中(您没有),而是将访问令牌粘贴到您的JS中,就像在回答中一样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.