使用Python客户端使用GAE端点

时间:2013-05-01 08:40:23

标签: python google-app-engine google-cloud-endpoints

我正在使用Google AppEngine端点来构建Web API。 我将使用Python编写的客户端来使用它。 我知道脚本是为了生成Android和iOS客户端API而提供的,但似乎没有任何可比性的Python。

再次编码所有内容似乎都是多余的。例如,消息定义基本相同。

无论如何更容易完成这项工作?

由于

2 个答案:

答案 0 :(得分:12)

您可以使用与端点兼容的Google APIs Client Library for Python

通常,您会使用service = build(api, version, http=http)构建客户端,例如service = build("plus", "v1", http=http)来构建客户端以访问Google+ API。

要将终结点用于您的终端,您可以使用:

service = build("your_api", "your_api_version", http=http, 
  discoveryServiceUrl=("https://yourapp.appspot.com/_ah/api/discovery/v1/"
                       "apis/{api}/{apiVersion}/rest"))

然后,您可以使用

访问您的API
result = service.resource().method([parameters]).execute()

答案 1 :(得分:3)

以下是端点helloworld问候语示例:

__author__ = 'robertking'

import httplib2
from apiclient.discovery import build

http = httplib2.Http()

service = build("helloworld", "v1", http=http,
  discoveryServiceUrl=("http://localhost:8080/_ah/api/discovery/v1/apis/helloworld/v1/rest"))

print service.greetings().listGreeting().execute()['items']

"""
prints
[{u'message': u'hello world!'}, {u'message': u'goodbye world!'}]
"""

现在我正在使用http。

相关问题