Google OAuth2服务帐户授权 [英] Google OAuth2 Service Accounts authorization

查看:713
本文介绍了Google OAuth2服务帐户授权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用服务帐户授权执行Google Drive API调用。



我正在调用API,但是文件.list 返回空集,同时驱动器不是空的。
我想我应该指定 prn 字段以便代表具体用户执行调用(我真的不知道在何时调用它未指定 prn )。问题是,当我指定 prn 授权时,会返回 access_denied 错误。

  {
error:access_denied
}

文档说我应该从控制台
http://support.google.com/a/bin/answer.py?hl=zh-CN&answer=162106



这是我所做的,但这并没有多大帮助,它仍然给我 access_denied





这里有什么不对?

解决方案

你几乎是对的。您确实需要授权您的应用访问域名的云端硬盘。为此,您必须将您选择的范围与可在API控制台中找到的服务帐户ID 相关联。这个关联是在你的域的管理面板中完成的,你发布了截图的whoch。



我认为你知道了,但不要忘记使用服务帐户电子邮件在您的Oauth2请求。



仅供参考,如果您不指定 prn ,您访问您的应用程序的驱动器通过Web UI访问

I'm trying to perform Google Drive API calls using "Service Accounts" authorization.

I'm calling the API, but files.list returns me empty set, meanwhile the drive is not empty. I guess I should specify prn field as well in order to perform call on behalf of the concrete user (I don't really get who is it called for when prn is not specified). The problem is that when I specify prn authorization returns me access_denied error.

{
  "error" : "access_denied"
}

Documentation says that I should enable client API access from control panel http://support.google.com/a/bin/answer.py?hl=en&answer=162106

Here is what I've done, but this doesn't help much, it still gives me access_denied.

What's wrong here?

解决方案

You are almost right. You indeed need to authorize your app to access domain's Drive. To do this you have to associate the scopes you chose with the service account id that you can find in your API console. This association is made in the administrative panel of your domain, of whoch you posted a screenshot.

I think you got that, but dont forget to use the service account email in your Oauth2 request.

FYI, if you dont specify prn , you access your application's drive, which cant be accessed via the Web UI

这篇关于Google OAuth2服务帐户授权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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