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


Google API gives login error when adding member to a group using admin sdk api

我使用谷歌api的简单Http请求在组中添加一个成员

我在我的谷歌管理控制台中建立了一个新项目,并有了一个密钥、客户端ID、客户端机密、服务帐户名,之后我编写了这段代码,将一个成员添加到一个组中。但这给了我错误。有人能告诉我哪里做错了吗

    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().

错误消息告诉您问题的具体原因。

Login required

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

如果您检查文档页面顶部的Members:insert方法,您会注意到它声明了。

需要授权

我不知道你使用的是什么语言,因为你还没有发布任何代码,但一个好的开始是查看文档