hangouts-chat - 任何人都可以用 php 分享工作的环聊聊天 api 示例吗?
问题描述
我正在寻找带有服务帐户的 Google 聊天 API 代码。我尝试了以下代码,但出现了一些错误,不确定我缺少什么。
include_once BP."/lib/google-api/vendor/autoload.php";
$client = new Google\Client();
$client->setAuthConfig(BP."/scripts/hangout/mytee-products-e6e5368c4246.json");
$client->setApplicationName("Client_Library_Examples");
$client->setScopes(['https://www.googleapis.com/auth/chat.bot']);
try{
$service = new Google_Service_HangoutsChat( $client );
print_r($service->spaces->listSpaces());
}
catch(Exception $e){
print $e->getMessage();
}
{“错误”:{“代码”:404,“消息”:“未找到请求的实体。”,“错误”:[{“消息”:“未找到请求的实体。”,“域”:“全局” ", "原因": "notFound" } ], "状态": "NOT_FOUND" } }
解决方案
考虑
注意:最近对 google-api-php-client Github 存储库的提交使用命名空间表示法更新了类名。
您正在使用命名空间表示法 ( Google\Client()
) 而未事先激活它。如果您不打算使用命名空间,则应采用不同的表示法。
解决方案
请参考此语法以Google_Client
在您的 PHP 脚本中使用 PHP 类方法:
include_once __DIR__ . '/path/to/vendor/autoload.php';
$client = new Google_Client();
$client->setAuthConfig(__DIR__."/path/to/credentials.json");
$client->setApplicationName("Your_Application_Name");
$client->setScopes(['https://www.googleapis.com/auth/chat.bot']);
try {
$service = new Google_Service_HangoutsChat( $client );
print_r($service->spaces->listSpaces());
} catch(Exception $e) {
print $e->getMessage();
}
参考
推荐阅读
- asp.net-mvc - InvalidOperationException:无法创建“Microsoft.AspNetCore.Identity.UserManager”类型的实例
- react-native - 发布 apk react-native 不加载图片
- flutter - Flutter - 如何对通知进行分组
- excel - VBA IE 下拉选择
- sympy - Sympy 求解的 ODE 不满足给定的初始条件
- javascript - 在 CSS 和 JS 中屏蔽 3D 旋转图像
- python - 模块“aioredis”没有属性“create_redis”
- java - 有没有办法让一个不在超类中的方法可以访问超类的实例变量?
- c++ - 将 IP 地址从字符串转换为 IPAddress (Arduino)
- android - Google Civics API:来自此客户端应用程序的请求
被封锁