致命错误:/twilio-php/Twilio/Rest/Client.php中带有'未知域通知'消息的未捕获异常'Twilio \ Exceptions \ TwilioException'

时间:2017-06-21 09:31:50

标签: php twilio twilio-api twilio-php

尝试使用Twilio Notify with 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

如何解决这个问题?谷歌搜索了很多,但没有运气。

2 个答案:

答案 0 :(得分:1)

我猜您使用的是代码中的5.x版本

所以使用此代码创建用户

$notification = $client
    ->notify->services($serviceSid)
    ->notifications->create([
        'identity' => '00000001',
        'body' => 'Hello Bob'
    ]);

echo $notification->sid;

答案 1 :(得分:0)

Twilio开发者传道者在这里。

您目前正在使用Twilio PHP 5.11.0。 Twilio Notify目前是测试版产品,因此未包含在主库中。

您需要install the alpha version of the library包含测试版和预览版产品。您可以使用composer with

安装它
composer require twilio/sdk:5.11.0-alpha1

至于身份,指的是通知中User的身份。要发送通知,您需要创建bindings,这些地址是您的用户接收通知的地址。然后,当您创建通知时,您将提供用户的身份以将通知发送到。