在 Twilio Programmable Chat 中,在 Laravel 后端,如何获取频道成员,给定频道代码
In Twilio Programmable Chat, in Laravel backend, how to get members of a channel, given the channel code
如何在我的 Laravel 后端获取频道的 Twilio 成员列表?我正在使用 Twilio 的可编程聊天 API。我尝试使用 ChannelInstance 成员方法或 属性,但我没有正确获取成员列表。有没有办法从 Laravel 内部做到这一点?我需要它被另一端的 iOS 应用程序使用(iOS 应用程序是客户端)。 Ios 应用程序从 Laravel 询问用户与之聊天的用户列表,所以我首先获取所有频道:
$params = $request->all();
$username = $params["username"];
$unl = strlen($username);
$twilio = new Client($this->sid, $this->authToken);
// Get all user's channels
$ucs = $twilio->chat->v2->services($this->serviceId)
->users($username)
->userChannels
->read(50);
// Try to find members of each channel
foreach ($ucs as $uc) {
$channel = $twilio->chat->v2->services($this->serviceId)
->channels($uc->channelSid)
->fetch();
print_r($channel->toArray());
}
在 print_r - ed 数组中,我有 uniqueName 和 friendlyName,它们连接了频道的两个参与者。但我更愿意只有两个对象或两个字符串来告诉我哪些是该频道的成员参与者。有办法吗?
此处为 Twilio 开发人员布道师。
在这种情况下,您只是在阅读有关频道的信息。相反,您应该 fetch the members from the channel.
foreach ($ucs as $uc) {
$channel_members = $twilio->chat->v2->services($this->serviceId)
->channels($uc->channelSid)
->members
->read([], 20);
print_r($channel_members);
}
要获得会员,我需要这样做:
$ucs = $twilio->chat->v2->services($this->serviceId)
->users($username)
->userChannels
->read(50);
foreach ($ucs as $uc) {
$channel_members = $twilio->chat->v2->services($this->serviceId)
->channels($uc->channelSid)
->members
->read([], 20);
foreach ($channel_members as $record) {
print($record->sid . "\n");
}
}
如何在我的 Laravel 后端获取频道的 Twilio 成员列表?我正在使用 Twilio 的可编程聊天 API。我尝试使用 ChannelInstance 成员方法或 属性,但我没有正确获取成员列表。有没有办法从 Laravel 内部做到这一点?我需要它被另一端的 iOS 应用程序使用(iOS 应用程序是客户端)。 Ios 应用程序从 Laravel 询问用户与之聊天的用户列表,所以我首先获取所有频道:
$params = $request->all();
$username = $params["username"];
$unl = strlen($username);
$twilio = new Client($this->sid, $this->authToken);
// Get all user's channels
$ucs = $twilio->chat->v2->services($this->serviceId)
->users($username)
->userChannels
->read(50);
// Try to find members of each channel
foreach ($ucs as $uc) {
$channel = $twilio->chat->v2->services($this->serviceId)
->channels($uc->channelSid)
->fetch();
print_r($channel->toArray());
}
在 print_r - ed 数组中,我有 uniqueName 和 friendlyName,它们连接了频道的两个参与者。但我更愿意只有两个对象或两个字符串来告诉我哪些是该频道的成员参与者。有办法吗?
此处为 Twilio 开发人员布道师。
在这种情况下,您只是在阅读有关频道的信息。相反,您应该 fetch the members from the channel.
foreach ($ucs as $uc) {
$channel_members = $twilio->chat->v2->services($this->serviceId)
->channels($uc->channelSid)
->members
->read([], 20);
print_r($channel_members);
}
要获得会员,我需要这样做:
$ucs = $twilio->chat->v2->services($this->serviceId)
->users($username)
->userChannels
->read(50);
foreach ($ucs as $uc) {
$channel_members = $twilio->chat->v2->services($this->serviceId)
->channels($uc->channelSid)
->members
->read([], 20);
foreach ($channel_members as $record) {
print($record->sid . "\n");
}
}