如何为Google Plus使用登录配额(plus.login范围)

时间:2015-07-29 07:18:31

标签: python google-api

我写了一个刮刀来获取一些用户的公开内容。这个刮刀取出评论,加上一个人,转发者和用户的帖子。如果您使用API​​密钥,则免费配额为每天10,000个请求:

   service = apiclient.discovery.build(service_name, service_version,
                                             developerKey=api_key)

我想使用登录配额来获取plusoners和resharers(people.list API调用)。但我无法将oauth用于此目的。也就是说,我没有任何用户。我想使用范围(https://www.googleapis.com/auth/plus.login)来获取plusoners和resharers。

在Java中,我认为程序是这样的:https://developers.google.com/android/reference/com/google/android/gms/common/api/GoogleApiClient.Builder

我如何为Python做到这一点?

1 个答案:

答案 0 :(得分:0)

有很多文档如何使用Oauth2.0对其进行身份验证,但是没有太多关于服务器端脚本如何在没有任何人员存在的情况下进行身份验证的信息。

我认为我找到了使用JWT最方便的方法。

from apiclient.discovery import build
from httplib2 import Http
from oauth2client.client import SignedJwtAssertionCredentials

private_key = open("MyProject.p12").read() 
client_email = 'EMAIL'
http_auth = credentials.authorize(Http())
credentials = SignedJwtAssertionCredentials(client_email, private_key, 'https://www.googleapis.com/auth/plus.login')
service.people().list(userId='me', collection='connected').execute()

请注意那些不像我这样小心的人:此外,这种身份验证方法对我来说并不实用,因为它适用于人()。列表API调用。但是,我想使用people()。listByActivity。