任何人都可以与php分享可使用的视频群聊聊天api示例吗?

时间:2020-11-04 12:09:39

标签: hangouts-chat

我正在寻找带有服务帐户的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,“消息”:“未找到请求的实体。”,“错误”:[{“消息”:“未找到请求的实体。”,“域” :“ global”,“ reason”:“ notFound”}],“ status”:“ NOT_FOUND”}}

1 个答案:

答案 0 :(得分:1)

注意事项

注意:最近commit到google-api-php-client Github存储库更新了带有名称空间符号的类名。

您正在使用名称空间表示法(Google\Client()),而未事先激活它。如果您不打算使用名称空间,则应该采用其他符号。

解决方案

请使用以下语法在PHP脚本中使用Google_Client 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();
}

参考文献

PHP Namespaces

Google PHP API Service Account

相关问题