1

私は得ています

 Error calling GET https://www.googleapis.com/admin/directory/v1/users/email@example.com.com: (403) Not Authorized to access this resource/api

実行中

        $client = new Google_Client();
        $client->setClientId(GOOGLEAPPS_CLIENT_ID);
        $client->setApplicationName(SITE_NAME);
        $key = file_get_contents(APPLICATION_PATH . 'googleapps-privatekey.p12');
        $assertion = new Google_AssertionCredentials(
                    GOOGLEAPPS_EMAIL_ADDRESS, // the service account name
                    array('https://www.googleapis.com/auth/admin.directory.user'), // see https://developers.google.com/admin-sdk/directory/v1/guides/authorizing
                    $key);
        $client->setAssertionCredentials($assertion);
        $service = new Google_DirectoryService($client);
        $user = $service->users->get('email@example.com');

https://developers.google.com/admin-sdk/directory/v1/guides/prerequisitesの指示に従い、[ API アクセスを有効にする] にチェックを入れました。Google API コンソールhttps://code.google.com/apis/consoleを使用してサービス アカウント キーを生成したところ、問題なく動作しました。

https://groups.google.com/forum/#!msg/google-api-php-client/LM-mwmuZe7I/IA_K5v1R1UMJ

Google PHP ライブラリを使用し、 https://code.google.com/p/google-api-php-client/wiki/OAuth2?hl=no#Service_Accountsの指示に従ってサービス アカウントを機能させてみました。彼らのコードへのデバッグ: 私は正常に承認し、期待どおりに新しいアクセス トークンを取得しています https://developers.google.com/accounts/docs/OAuth2ServiceAccount

読んだすべての内容で、すべてをオンに切り替えたと表示されているのに、「このリソース/API にアクセスする権限がありません」というメッセージが表示される理由がわかりません。何か案は?

4

4 に答える 4

4

ちょうどそれが働いた。oAuth がそのユーザーに対してあなたを承認するように、管理者のユーザーの電子メールを含める必要があります。試す

    $assertion = new Google_AssertionCredentials(
                GOOGLEAPPS_EMAIL_ADDRESS, // the service account name
                array('https://www.googleapis.com/auth/admin.directory.user'), // see https://developers.google.com/admin-sdk/directory/v1/guides/authorizing
                $key,
                'notasecret',
                'http://oauth.net/grant_type/jwt/1.0/bearer',
                'admin_user@email.com'
    );

また、その後、管理コンソール -> セキュリティ -> 詳細設定 -> 認証 -> OAuth クライアント アクセスの管理から、要求している範囲の client_id を承認する必要があります。

于 2014-04-04T12:55:55.757 に答える
1

エラーが発生した場合

Class 'Google_AssertionCredentials' not found

あなたは新しいライブラリを使用しており、Google_AssertionCredentials現在はGoogle_Auth_AssertionCredentials.

参照: https://github.com/google/google-api-php-client/blob/master/src/Google/Auth/AssertionCredentials.php

于 2015-02-24T12:13:57.610 に答える