2016-06-08 38 views
0

我正嘗試使用google directory api創建一個組。傳遞給Google_Service_Directory_Groups_Resource :: insert的參數1必須是Google_Service_Directory_Group的一個實例,

但我得到這個錯誤

Catchable fatal error: Argument 1 passed to Google_Service_Directory_Groups_Resource::insert() must be an instance of Google_Service_Directory_Group, array given, called in C:\xampp\htdocs\groups\index.php on line 94 and defined in C:\xampp\htdocs\groups\google-api-php-client\src\Google\Service\Directory.php on line 2196

我已經使用這個代碼

<?php 

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

$clientId = 'jkdjdjkdjkdjk'; 


$serviceAccountName = 'gserviceaccount.com'; 

$delegatedAdmin = '[email protected]'; 

$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'=>'[email protected]'); 
    $list = $dir->groups->insert($postBody); 
    print_r($list); 

回答

0

您需要更改在$ postBody數組:

$postBody = new Google_Service_Directory_Group(); 
$postBody->email = '[email protected]'; 

$list = $dir->groups->insert($postBody); 
print_r($list); 
相關問題