Google Apps マーケットプレイスからインストールされたアプリで、ユーザーが Google Apps ドメインの管理者であるかどうかを確認しようとしています。
これをmanifest.xmlに追加しました:
<Scope id="Provisioning API">
<Url>https://apps-apis.google.com/a/feeds/user/#readonly</Url>
<Reason>This application can list domain users to give them permissions.</Reason>
</Scope>
次に、テスト ハンドラーを設定して動作させます。
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
import gdata.alt.appengine
import gdata.apps.service
import gdata.auth
# App id, key and secret from the Google Apps Marketplace.
APPLICATION_ID = 'XXX'
CONSUMER_KEY = 'XXX'
CONSUMER_SECRET = 'XXX'
class SetupHandler(webapp.RequestHandler):
def get(self, *args):
# The domain where this app is installed.
domain = 'my_customer_domain.com'
# A username to check.
username = 'webmaster'
sig_method = gdata.auth.OAuthSignatureMethod.HMAC_SHA1
service = gdata.apps.service.AppsService(source='tipfy-com',
domain=domain)
service.SetOAuthInputParameters(sig_method, CONSUMER_KEY,
consumer_secret=CONSUMER_SECRET,
two_legged_oauth=True,
requestor_id=APPLICATION_ID)
service.ssl = True
service.debug = True
gdata.alt.appengine.run_on_appengine(service)
lookup_user = service.RetrieveUser(username)
if lookup_user.login.admin == 'true':
res = username + ' is an admin.'
else:
res = username + ' is not an admin.'
self.response.out.write(res)
app = webapp.WSGIApplication([
('/.*', SetupHandler),
], debug=True)
def main():
util.run_wsgi_app(app)
if __name__ == '__main__':
main()
しかし、401 応答 (「不明な認証ヘッダー」) が返されます。何を間違っているのか、さらにデバッグする方法がわかりません。
- マニフェストのエントリは正しいですか?
user.email()ユーザーのユーザー名とドメインを取得するために分割しても問題ありませんか? (私はそれをデバッグしました。私の場合は、「webmaster」と「example.com」を取得しました。これは、アプリがインストールされたユーザーと Google Apps ドメインでした)。
私は何が欠けていますか?
編集:何らかの理由で、管理パネルは、提供されたスコープへのアクセスを許可する許可を求めませんでした。許可した後、上記のコードは機能しました。だから、実際の例としてそれを取ってください!