我尝试使用Twilio Notify和PHP向移动设备发送推送通知,首先使用以下代码创建一个用户
require_once 'vendor/autoload.php';
use Twilio\Rest\Client;
$accountSid = "sid";
$authToken = "your_auth_token";
$serviceSid = "serviceSid";
// Initialize the client
$client = new Client($accountSid, $authToken);
// Create a user
$user = $client
->notify->services($serviceSid)
->users->create([
'identity' => 'push token', //am not sure what is identity also?
'segment' => ['segmentName']
]);
// print_r($user);
echo $user->sid;在中获取异常
Fatal error: Uncaught exception 'Twilio\Exceptions\TwilioException' with message 'Unknown domain notify' in Twilio/Rest/Client.php如何解决这个问题?我用谷歌搜索了很多,但没什么好结果。
发布于 2017-06-21 18:32:50
Twilio开发者的布道者在这里。
您当前使用的是Twilio PHP 5.11.0。Twilio Notify目前是测试版产品,所以没有包含在主库中。
您将需要install the alpha version of the library,包括测试版和预览产品。你可以用composer来安装它
composer require twilio/sdk:5.11.0-alpha1至于标识,是指Notify中User的标识。要发送通知,您需要创建bindings,这是您的用户接收通知的地址。然后,在创建通知时,您需要提供要向其发送通知的用户的身份。
发布于 2017-06-21 17:46:14
我猜您在代码中使用的是5.x版本
所以使用以下代码来创建一个用户
$notification = $client
->notify->services($serviceSid)
->notifications->create([
'identity' => '00000001',
'body' => 'Hello Bob'
]);
echo $notification->sid;https://stackoverflow.com/questions/44672155
复制相似问题