Twilio API-无法将电话号码分配给Messaging Service

问题描述 投票:0回答:1

我正在尝试通过Twilio API将新创建的电话号码分配给现有的消息服务。到目前为止,这是我的代码:

创建消息服务

$createService = $twilio->messaging->v1->services
  ->create([
    "friendlyName" => "Service",
    "inboundRequestUrl" => "https://example.com/folder/file.php"
  ]
);

$messagingServiceId = $createService->sid;

创建电话号码并分配给消息服务

$smsNumber = $_POST["smsNumber"];

$addPhoneNumber = $twilio->incomingPhoneNumbers
  ->create([
    "phoneNumber" => $smsNumber,
    "smsApplicationSid" => $messagingServiceId
  ]
);

使用先前的代码,我能够创建消息服务,该电话号码已添加到该帐户,但未分配给消息服务。

我在这里想念什么?

感谢您的帮助。

twilio twilio-api twilio-php
1个回答
0
投票

查看电话号码资源的Create A Phone Number代码示例。

<?php

// Update the path below to your autoload.php,
// see https://getcomposer.org/doc/01-basic-usage.md
require_once '/path/to/vendor/autoload.php';

use Twilio\Rest\Client;

// Find your Account Sid and Auth Token at twilio.com/console
// DANGER! This is insecure. See http://twil.io/secure
$sid    = "ACCOUNT_SID";
$token  = "your_auth_token";
$twilio = new Client($sid, $token);

$phone_number = $twilio->messaging->v1->services("MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
                                      ->phoneNumbers
                                      ->create("PNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" // phoneNumberSid
                                      );

print($phone_number->sid);
© www.soinside.com 2019 - 2024. All rights reserved.