5

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 ドメインでした)。

私は何が欠けていますか?

編集:何らかの理由で、管理パネルは、提供されたスコープへのアクセスを許可する許可を求めませんでした。許可した後、上記のコードは機能しました。だから、実際の例としてそれを取ってください!

4

3 に答える 3

2

スコープが機能するためにアプリを再度追加する必要はありません。GoogleApps 管理ダッシュボードのアプリケーション設定で、「アクセスを許可」し、データ アクセスが「許可」されていることを確認してください。それ以外の場合は、そのアクセスを許可してください。

ローカルホストのテストでは、実稼働 (ユーザー名が含まれる) とは異なり、完全な電子メールが含まれているため、分割user.email()は私にとって魅力のように機能します。user.nickname()

リクエストしているユーザーがadminであることを確認してください。

于 2011-05-19T14:58:23.930 に答える
0

私はまったく同じ問題に遭遇しました。

不明な認証ヘッダー

エラー 401

Google Apps の無料版を使用していますが、これがこの問題の根本的な原因でしょうか? 私が知っているように、Provisioning API はプレミアム アカウントのみをサポートしています。

于 2011-09-18T09:51:11.377 に答える
0

管理 API [プロビジョニング API など] が Google Apps のエディションで利用できるようになりました。

http://googleappsdeveloper.blogspot.com/2011/12/more-administrative-apis-now-available.html

于 2011-12-25T19:28:59.463 に答える