跳转到主要内容

Django应用程序存储Google API OAuth凭证。

项目描述

将Google OAuth凭证存储在Django ORM中,以便于API服务访问。

安装

  1. 安装或添加 django-google-credentials 到您的Python路径。

  2. google_credentials 添加到您的 INSTALLED_APPS 设置。

  3. google_credentials URL包含添加到项目的 urls.py 文件

    url(r'^google-credentials/', include('google_credentials.urls')),
  4. Google API控制台 上创建您的项目,指定重定向URL为 http://your.domain.com/google-credentials/callback(或如上所述设置您的 urls.py)。

  5. 将以下设置添加到您的项目 settings.py 文件中,并用从Google获取的值填充,例如:

    GA_CLIENT_ID = '32749234234.apps.googleusercontent.com'
    GA_CLIENT_SECRET = 'DKSFY87sd6fHJGdsf6'
    GA_SCOPE = 'https://www.googleapis.com/auth/analytics.readonly'
    GA_REDIRECT_URI = 'http://your.domain.com/google-credentials/callback'
  6. 运行 syncdb 以生成所需的模型。

用法

在您开始使用服务之前,您必须使用您的Google账户授权它。为此,请在您的浏览器中打开http://your.domain.com/google-credentials/authorize

一旦授权,您可以按照以下方式检索服务以进行进一步查询

from google_credentials import utils

service = utils.get_service()

要清除以前生成的凭据,请在您的浏览器中打开http://your.domain.com/google-credentials/purge

由以下机构支持