传递给Google_Service_Directory_Groups_Resource :: insert的参数1必须是Google_Service_Directory_Group的实例,

时间:2016-06-08 11:50:57

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

我正在尝试使用google directory api创建一个组。

但是我收到了这个错误

  

可捕获的致命错误:参数1传递给   Google_Service_Directory_Groups_Resource :: insert()必须是一个实例   Google_Service_Directory_Group,给定的数组,调用   第94行的C:\ xampp \ htdocs \ groups \ index.php并在中定义   C:\ XAMPP \ htdocs中\组\谷歌的API的PHP客户端的\ src \谷歌\服务\ Directory.php   在线2196

我已使用此代码

<?php

include_once 'google-api-php-client/src/Google/autoload.php';

$clientId = 'jkdjdjkdjkdjk';


$serviceAccountName = 'gserviceaccount.com';

$delegatedAdmin = 'myemailid@gmail.com';

$keyFile = 'myfile.p12';


$appName = 'Example App';


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


$creds = new Google_Auth_AssertionCredentials(
    $serviceAccountName,
    $scopes,
    file_get_contents($keyFile)
);

$creds->sub = $delegatedAdmin;

/**
 * Create Google_Client for making API calls with
 */
$client = new Google_Client();
$client->setApplicationName($appName);
$client->setClientId($clientId);
$client->setAssertionCredentials($creds);


$dir = new Google_Service_Directory($client);


$postBody = array('email'=>'sales_group@domain.com');
    $list = $dir->groups->insert($postBody);
    print_r($list);

1 个答案:

答案 0 :(得分:0)

您需要在$ postBody中更改数组:

$postBody = new Google_Service_Directory_Group();
$postBody->email = 'sales_group@domain.com';

$list = $dir->groups->insert($postBody);
print_r($list);