标签: oauth2client

如何在 GNOME 3.0 shell 扩展中访问 OAuth 2.0、REST API?

如果我想通过 GNOME shell 扩展访问它下面的 REST API,我将如何从浏览器环境移植 OAuth 2.0 隐式授权流?如何通过登录屏幕将用户重定向到 OAuth 2.0 决策端点?

如果 OAuth 2.0 REST API 无法通过其他方式将 Web 服务与 shell 扩展集成?

javascript rest gnome-shell-extensions oauth2client

5
推荐指数
0
解决办法
232
查看次数

Google oauth2client 的 EOF 错误(Python、google-app-engine)

我目前在我的 Python 网络应用程序中使用 oauth2client 以使用 Google 的日历 API。

我将 oauth2client 复制到我目录的根文件夹中,并按照https://developers.google.com/google-apps/calendar/instantiate 上的说明进行操作。这意味着我的代码看起来像:

import httplib2
import gflags

from apiclient.discovery import build
from oauth2client.file import Storage
from oauth2client.client import OAuth2WebServerFlow
from oauth2client.tools import run

FLAGS = gflags.FLAGS

FLOW = OAuth2WebServerFlow(
client_id='myid',
client_secret='mycode',
scope='https://www.googleapis.com/auth/calendar',
user_agent='myapp/4')

storage = Storage('calendar.dat')
credentials = storage.get()
if credentials is None or credentials.invalid == True:
    credentials = run(FLOW, storage)
Run Code Online (Sandbox Code Playgroud)

ID,密钥都来自我的 Google Cloud Console 帐户,所以它们应该是正确的。我在日志中看到以下错误:


ERROR    2013-12-10 14:03:33,983 api_server.py:112] Received a request without request_id: service_name: "remote_socket"
method: "Close" …
Run Code Online (Sandbox Code Playgroud)

google-app-engine google-api oauth2client

5
推荐指数
0
解决办法
1026
查看次数

oauth2client凭据refresh_token变为null

Backgound

  1. 我使用google-api-python-client django_sample为Google API提供了access_token .
  2. 要进行离线访问,我已经添加了FLOW.params['access_type'] = 'offline'.
  3. 存储credentials_json = credentials.to_json().它包含一个refresh_token.
  4. 恢复了凭据Credentials.new_from_json(credentials_json).
  5. 使用此凭据来获取访问权限credentials.authorize(http).
  6. 工作得很完美=)

问题

  1. 我每5分钟做一次.
  2. 在每次迭代中,我都存储了凭据并将其打印出来.
  3. 1小时45分钟后,"refresh_token"变为空.
  4. 此时代码停止工作=(

我的问题

  1. 难道Credentials类刷新它会自动的令牌?
  2. 如果没有,我应该在什么时候打电话credentials.refresh(http)

谢谢!

oauth2client google-oauth google-api-python-client

5
推荐指数
1
解决办法
2187
查看次数

如何在django中存储google oauth令牌:存储或数据库

Google API python客户端对Django具有特殊的支持,在Google(https://developers.google.com/api-client-library/python/guide/django)提供的示例中,oauth2client.django_orm.Storage类为用于存储和检索凭据对象。

然而,我发现很多的例子(https://github.com/jgmize/django-google-drive/tree/master/gdrive/gdoauth2https://github.com/praekelt/django-google-credentials/tree/ master / google_credentials等)将凭据放入用户个人资料的CredentialsField字段中,并将其保存到数据库中。

两种方法的优点/缺点是什么?有偏好吗?

谢谢

django google-api google-api-client oauth2client google-oauth

5
推荐指数
1
解决办法
1092
查看次数

GAE - 无法从BigQuery API获取URL

我们的集成平台现在每天都会收到几个"无法获取URL:..."错误.我不知道这是什么原因.

第一个GAE尝试通过BigQuery API从应用程序内部向OAQuery授权OAuth2 .它每秒都会尝试超过30秒(这只是30条相似线中的一条):

2015-05-12 05:59:02.727
URL being requested: https://www.googleapis.com/bigquery/v2/projects/XXX/jobs/job_w-z5K2zQObXeSaLy3hx7m4FOMXc?alt=json
Run Code Online (Sandbox Code Playgroud)

下面是跟踪本身(就在上面的日志之后):

File "/base/data/home/apps/s~XXX/processes:uno.383135852015228853/connectors/connector_XXX_v1_0.py", line 189, in send
    status = self._verify_status(resp, content)
  File "/base/data/home/apps/s~XXX/processes:uno.383135852015228853/connectors/connector_XXX_v1_0.py", line 250, in _verify_status
    jobId=jobReference).execute()
  File "/base/data/home/apps/s~XXX/processes:uno.383135852015228853/modules/oauth2client/util.py", line 128, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/base/data/home/apps/s~XXX/processes:uno.383135852015228853/modules/apiclient/http.py", line 676, in execute
    body=self.body, headers=self.headers)
  File "/base/data/home/apps/s~XXX/processes:uno.383135852015228853/modules/oauth2client/util.py", line 128, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/base/data/home/apps/s~XXX/processes:uno.383135852015228853/modules/oauth2client/client.py", line 490, in new_request
    redirections, connection_type)
  File "/base/data/home/apps/s~XXX/processes:uno.383135852015228853/modules/httplib2/__init__.py", line 1570, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, …
Run Code Online (Sandbox Code Playgroud)

google-app-engine python-2.7 google-bigquery oauth2client google-oauth

5
推荐指数
1
解决办法
270
查看次数

'AttributeError:'模块'对象在将oauth2client与Google Calendar结合使用时没有属性'file''

我正在使用google calendars python api(https://developers.google.com/google-apps/calendar/quickstart/python#step_3_set_up_the_sample)的示例脚本来尝试打印出所有日历事件.但是我收到的错误是:

AttributeError: 'module' object has no attribute 'file'
Run Code Online (Sandbox Code Playgroud)

从线

store = oauth2client.file.Storage(credential_path)
Run Code Online (Sandbox Code Playgroud)

我在文档中找不到对此类错误的引用.有没有其他人遇到过这个?

干杯,杰克

python calendar google-calendar-api oauth-2.0 oauth2client

5
推荐指数
1
解决办法
4728
查看次数

使用 oauth2 和 Google API 无法识别的参数

我在某些脚本中使用了 Google API 服务,但遇到了一些问题。这个错误很奇怪,但我们走了。我有一个列出我的 Google Drive 文件的脚本。

from apiclient import discovery
from httplib2 import Http
from oauth2client import file, client, tools

SCOPES = 'https://www.googleapis.com/auth/drive.readonly.metadata'
store = file.Storage('storage.json')
creds = store.get()
if not creds or creds.invalid:
    flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
    creds = tools.run_flow(flow, store)
DRIVE = discovery.build('drive', 'v3', http=creds.authorize(Http()))

files = DRIVE.files().list().execute().get('files', [])
for f in files:
    print(f['name'], f['mimeType'],f['id'])
Run Code Online (Sandbox Code Playgroud)

它运行良好,我client_secret.json从 Google API下载并将其保存在同一文件夹中,然后我启动脚本以检查一切正常。

然后我开始编辑我的文件以改变我执行它的方式而不是读取文件,而是调用脚本并将client_idclient_secret字符串发送到脚本,最终版本是这样的:

import sys
from apiclient import discovery
from httplib2 import Http
from oauth2client …
Run Code Online (Sandbox Code Playgroud)

python google-api python-3.x oauth2client google-api-python-client

5
推荐指数
1
解决办法
909
查看次数

使用 oauth2client 创建 google api 凭据(来自具有范围和委托帐户的服务帐户)

要访问 GMail API(和拟人化调用),我使用服务帐户(从 Google Cloud Platform 创建)。我的 json 文件看起来像这样

{
"type": "service_account",
"project_id": "[PROJECT-ID]",
"private_key_id": "[KEY-ID]"
"private_key": "-----BEGIN PRIVATE KEY-----\n[PRIVATE-KEY]\n-----END PRIVATE KEY-----\n",
"client_email": "[SERVICE-ACCOUNT-EMAIL]",
"client_id": "[CLIENT-ID]",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://accounts.google.com/o/oauth2/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/[SERVICE-ACCOUNT-EMAIL]"
}
Run Code Online (Sandbox Code Playgroud)

我还使用oauth2client库来简化操作,但我找不到创建凭据然后指定范围和委托帐户的方法。

我试过

from oauth2client import service_account

self._credentials = service_account.ServiceAccountCredentials.from_json(SERVICE_ACCOUNT_JSON_CONTENT)
self._credentials = self._credentials.create_scoped([u'https://www.googleapis.com/auth/gmail.send'])
self._credentials = self._credentials.create_delegated(MY_USER)
        self._client = discovery.build(u'gmail', u'v1', credentials=self._credentials)
Run Code Online (Sandbox Code Playgroud)

但我收到错误,因为它需要 PKCS-8 密钥。

我怎样才能做到这一点 ?(如果有帮助的话,我的代码在 App Engine Flex 上运行)

谢谢

oauth2client google-oauth service-accounts app-engine-flexible

5
推荐指数
1
解决办法
2万
查看次数

如何在不将 client_secret.json 检查到版本控制的情况下使用 Google API?

我正在开发一个项目,根据https://12factor.net/config,我们不在代码中使用凭据之类的东西,而是在环境变量中使用。

我正在考虑使用 Google Sheets API 来整理数据库中的一些数据并将其放入 Google 表格中。这是来自https://developers.google.com/sheets/api/quickstart/python的部分示例脚本:

from __future__ import print_function
from apiclient.discovery import build
from httplib2 import Http
from oauth2client import file as oauth_file, client, tools

# Setup the Sheets API
SCOPES = 'https://www.googleapis.com/auth/spreadsheets.readonly'
store = oauth_file.Storage('token.json')
creds = store.get()
if not creds or creds.invalid:
    flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
    creds = tools.run_flow(flow, store)
service = build('sheets', 'v4', http=creds.authorize(Http()))
Run Code Online (Sandbox Code Playgroud)

首先,从文档中我不清楚这个示例中应该包含什么'token.json'以及'credentials.json'应该是什么。从 API 控制台的“凭据”选项卡中,我下载了client_secret_<long suffix>.json如下所示的文件:

{"installed":{"client_id":"[our_client_id]","project_id":"nps-survey-1532981793379","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://accounts.google.com/o/oauth2/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"[our_client_secret]","redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"]}}
Run Code Online (Sandbox Code Playgroud)

这个 JSON 文件应该是'token.json'本例中的 …

python google-api oauth2client google-oauth google-sheets-api

4
推荐指数
1
解决办法
7148
查看次数

将 google-auth 与 gspread 一起使用时,“'Credentials' 对象没有属性'access_token'”

我想使用gspread模块从 Python 编辑 Google 表格。的设置说明包含下面的例子:

import gspread
from oauth2client.service_account import ServiceAccountCredentials

scope = ['https://spreadsheets.google.com/feeds',
         'https://www.googleapis.com/auth/drive']

credentials = ServiceAccountCredentials.from_json_keyfile_name('gspread-april-2cd … ba4.json', scope)

gc = gspread.authorize(credentials)
Run Code Online (Sandbox Code Playgroud)

但是,根据https://pypi.org/project/oauth2client/,oauth2client库已被弃用。所以我尝试将其调整如下,使用google-auth

import gspread
from google.oauth2 import service_account

credentials = service_account.Credentials.from_service_account_file(
    'my_client_secrets.json')

scoped_credentials = credentials.with_scopes(
    ['https://www.googleapis.com/auth/spreadsheets'])

gc = gspread.authorize(scoped_credentials)
Run Code Online (Sandbox Code Playgroud)

不幸的是,我遇到了以下错误:

(lucy-web-CVxkrCFK) bash-3.2$ python nps.py
Traceback (most recent call last):
  File "nps.py", line 54, in <module>
    gc = gspread.authorize(scoped_credentials)
  File "/Users/kurtpeek/.local/share/virtualenvs/lucy-web-CVxkrCFK/lib/python3.7/site-packages/gspread/__init__.py", line 38, in authorize
    client.login()
  File "/Users/kurtpeek/.local/share/virtualenvs/lucy-web-CVxkrCFK/lib/python3.7/site-packages/gspread/client.py", …
Run Code Online (Sandbox Code Playgroud)

python google-api google-authentication oauth2client

4
推荐指数
2
解决办法
9105
查看次数