如何定义正确的GAE端点范围

时间:2015-05-07 03:14:08

标签: google-app-engine

在Google App Engine GAE1中,我在Tastypie中实现了一个REST API:

(伪API) https://mygae.google.com/api_rest/api/v1/myapi/?format=json(从浏览器访问时有效)

以下代码是从另一个GAE2到OAuth2访问GAE1 REST API,key.p12是从GAE控制台创建的。

import httplib2
import pprint
import sys

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

f = file('~/key.p12', 'rb')
key = f.read()
f.close()

credentials = SignedJwtAssertionCredentials(
      'xxxxxxxx@developer.gserviceaccount.com',
      key,
      scope='https://mygae.google.com/api_rest/api/')

http = httplib2.Http()
http = credentials.authorize(http)

API_ROOT = 'https://mygae.google.com/'
DISCOVERY_URL = API_ROOT + '/api_rest/api/{apiVersion}/{api}/?format=json'

#### Invalid scope ERROR will happen here.
service = build("myapi", "v1", http=http,
                discoveryServiceUrl=DISCOVERY_URL)

lists = service.tasklist
pprint.pprint(lists)

但是,它的范围错误无效:

-----错误信息----

oauth2client.client.AccessTokenRefreshError:invalid_scope:scope ='https://mygae.google.com/api_rest/api/无效范围。

在这种情况下如何定义正确的范围? OAuth2是否适用于此案例?这是访问GAE1 API的正确方法吗?如果没有,如何访问GAE 1 API?请提供示例代码。

正如你所看到的,我对“范围”感到困惑。范围是谷歌API或我创建的API?范围与发现URL之间的关系是什么?

0 个答案:

没有答案
相关问题