使用admin sdk api将成员添加到组时,Google API会出现登录错误

时间:2016-05-10 12:22:55

标签: php google-api google-api-php-client admin-sdk

我正在使用google api的Simple Http请求添加组中的成员

我在google管理控制台中设置了一个新项目,并拥有密钥,clientid,客户端密钥,服务帐户名称,之后我编写此代码以向组中添加成员。但它给了我错误。任何人都可以建议我做错了什么

    include_once __DIR__ . '/GoogleClientApi/vendor/autoload.php';
    include_once __DIR__. '/GoogleClientApi/src/Google/Auth/Google_AssertionCredentials.php';

    $clientId = 'xxxxxxxxxxxxc7iqi.apps.googleusercontent.com';

    -----------------------------------
       -----------------------------------

    $scopes = array(
        'https://www.googleapis.com/auth/admin.directory.group',
        'https://www.googleapis.com/auth/admin.directory.user'
    );

    ------------------------------
------------------------------------------

    $client = new Google_Client();
    $client->setApplicationName($appName);
    $client->setClientId($clientId);
    $client->setAssertionCredentials($creds); // This line gives the error

此代码给出了以下错误:

Fatal error: Call to undefined method Google_Client::setAssertionCredentials().

1 个答案:

答案 0 :(得分:1)

错误消息可以准确地告诉您问题所在。

Login required

要访问私人数据,例如将用户添加到管理员帐户,您需要先进行身份验证。

如果您在文档页面的顶部查看该方法Members: insert,您会注意到它的状态。

  

需要authorization

我不知道您使用的语言是什么,因为您没有发布任何代码,但一个好的起点是检查documentation