3

これは、この質問のフォローアップの質問です:

秘密鍵の作成に成功し、サーバー間認証の概念に関する Google ドキュメントのさまざまなページを読みました。

App Engine アプリケーション (Python) が Google カレンダーにアクセスし、イベントをカレンダーに投稿することを承認するには、JWT を作成する必要があります。ソースから、JWT を作成するためoauth2clientに使用する必要があるようです。oauth2client.client.SignedJwtAssertionCredentials

現時点で欠けているのは、JWT を作成し、それを使用して Google カレンダー用の App Engine アプリケーションを認証するために必要なさまざまな手順のサンプル Python コードです。また、SignedJwtAssertionCredentialsソースから、署名を実行するには App Engine と互換性のあるライブラリが必要なようです。

誰でもこれに光を当てることができますか?

4

1 に答える 1

8

掘り下げた後、OAuth2 認証に基づくサンプルをいくつか見つけました。このことから、カレンダー API にアクセスするための JWT を作成する次の簡単なサンプルを作成しました。

import httplib2
import pprint

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

# Get the private key from the Google supplied private key file.
f = file("your_private_key_file.p12", "rb")
key = f.read()
f.close()

# Create the JWT
credentials = SignedJwtAssertionCredentials(
  "xxxxxxxxxx@developer.gserviceaccount.com", key,
  scope="https://www.googleapis.com/auth/calendar"
)

# Create an authorized http instance
http = httplib2.Http()
http = credentials.authorize(http)

# Create a service call to the calendar API
service = build("calendar", "v3", http=http)

# List all calendars.
lists = service.calendarList().list(pageToken=None).execute(http=http)
pprint.pprint(lists)

これを Google App Engine で機能させるには、アプリで PyCrypto を有効にする必要があります。これは、app.yamlファイルに次を追加することを意味します。

libraries:
- name: pycrypto
  version: "latest"
于 2013-10-16T21:05:13.580 に答える