【问题标题】:Argument 1 passed to Google_Service_Directory_Groups_Resource::insert must be an instance of Google_Service_Directory_Group,传递给 Google_Service_Directory_Groups_Resource::insert 的参数 1 必须是 Google_Service_Directory_Group 的实例,
【发布时间】:2016-06-08 11:50:56
【问题描述】:

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

但是我收到了这个错误

可捕获的致命错误:参数 1 传递给 Google_Service_Directory_Groups_Resource::insert() 必须是一个实例 Google_Service_Directory_Group,给定数组,调用 C:\xampp\htdocs\groups\index.php 在第 94 行并在 C:\xampp\htdocs\groups\google-api-php-client\src\Google\Service\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);

【问题讨论】:

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


    【解决方案1】:

    您需要将 $postBody 中的数组更改为:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-10
      • 2015-10-16
      • 2018-03-12
      • 2017-12-24
      相关资源
      最近更新 更多