【问题标题】:Where to find a complete Google Directory API reference for PHP?在哪里可以找到 PHP 的完整 Google Directory API 参考?
【发布时间】:2015-07-04 20:34:40
【问题描述】:

我正在尝试用 PHP 编写一段代码,允许管理员将用户添加到我的应用程序中。 我在https://developers.google.com/api-client-library/php/start/get_started 找到了一些“入门”页面以及一些授权和身份验证教程 另外,我在https://github.com/google/google-api-php-client#basic-example 找到了一个非常简单的示例。可以在这里找到一个很好的:https://stackoverflow.com/a/26532344。 但是,我仍然需要做一些事情,比如创建用户、删除用户等。但我似乎无法找到关于目录 API 方法的任何好的参考或文档。例如,基于最后提到的示例,我知道我应该使用“dir->users->insert()”方法来创建一个用户(我只是通过在我的 IDE 中搜索建议找到的,但我没有不知道要传递给方法的参数以及它们的含义)。 我知道有关于插入用户的 API 参考,但同样,它并没有具体说明如何用 PHP 编写它。 那么,是否有任何完整而透彻的参考和文档来描述 Google Directory API for PHP 的所有方法?

【问题讨论】:

  • 我的问题有什么问题(因为我得到了 -1 票)?

标签: google-api-php-client


【解决方案1】:

这个问题已有 6 年历史了,但你在谷歌上搜索这个问题仍然会想到什么。 (而且答案仍然没有帮助)

无论如何,这是一个使用 PHP Directory API 创建新用户的超级基本示例:

// Get your client somehow (there's lot of example code for that part)
$service = new Google_Service_Directory($client);
// Build the UserName Object
$user_name = new Google_Service_Directory_UserName();
$user_name->givenName = 'TestUSer1First';
$user_name->familyName = 'TestUSer1Last';
    
// Build the User Object
$user = new Google_Service_Directory_User();
$user->password = "testuser1";
$user->hashfunction = "SHA-1";
$user->primaryEmail = "testuser1@domain.com";
$user->password = "testuser1password";
$user->setName($user_name);
$results = $service->users->insert($user);

不幸的是,Google 没有记录他们的任何客户端 API 包装器,但是如果您在 github 上查看它们的代码,它们的代码相对来说是不言自明的。
例如:

https://github.com/googleapis/google-api-php-client-services/blob/master/src/Google/Service/Directory/User.php

https://github.com/googleapis/google-api-php-client-services/blob/master/src/Google/Service/Directory/UserName.php

https://github.com/googleapis/google-api-php-client-services/blob/master/src/Google/Service/Directory/Resource/Users.php

【讨论】:

    【解决方案2】:

    听起来您正在寻找API referenceuser insert method 的API 参考

    【讨论】:

    • 嗯,不是真的。这些参考资料的描述非常笼统,并没有说明在 PHP 中使用哪种方法。不过谢谢你的回答。
    • 这些 API 文档会告诉您参数是什么以及它们的含义,这样您就可以开始了。
    • 确实如此,但它并没有帮助我在 PHP 中实现它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-19
    • 2020-10-06
    • 1970-01-01
    • 1970-01-01
    • 2013-04-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多