首页 > 解决方案 > 无法将数字从子账户移动到主账户 (Twilio)

问题描述

我正在使用 Twilio PHP 帮助程序库。

我有几个存储在数据库中的子帐户凭据。每个子帐户通常有几个与之关联的拨出呼叫者 ID。

我使用每个子帐户的凭据来获取传出CallerIds。

从返回的数据中,我获取子账户 SID (AC) 和数字 SID (PN)。

我按照文档进行操作,每次尝试使用子账户中的数字更新主账户时都会收到错误消息。

捕获异常:[HTTP 404] 无法更新记录:未找到请求的资源 /2010-04-01/Accounts/ACxxxxxxxxxxxxxx/IncomingPhoneNumbers/PNxxxxxxxx.json

我检查了帐户 sids 和 number sids,它们是正确的。

知道我在哪里出错了吗?

这是我在 foreach 中进行的尝试,它为每个子帐户提供凭据。

try
{
    $client = new Client($sid, $token); //subaccount sid and token from not shown foreach
    $caller_ids = $client->outgoingCallerIds->read();

    foreach ($caller_ids as $caller_id)
    {
        $phone_number = $caller_id->phoneNumber;
        $friendly_name = $caller_id->friendlyName;
        $number_sid = $caller_id->sid;
        $account_sid = $caller_id->accountSid;

        $incoming_phone_number = $master_account->incomingPhoneNumbers("$number_sid")
            ->update(
                array("accountSid" => "$account_sid")
            );
    }
}

标签: phptwilio

解决方案


Twilio 开发人员布道者在这里。

我认为这里的问题是您使用主帐户 sid 来引用位于子帐户中的号码,从而得到 404。相反,您应该从主帐户的帐户列表中选择子帐户,并使用该子帐户对象转接时参考号码。

例如:

$subaccount = $master_account->accounts($subaccount_sid);
$incoming_phone_number = $subaccount->incomingPhoneNumbers($number_sid)
        ->update(
            array("accountSid" => $master_account->sid)
        );

让我知道这是否有帮助。


推荐阅读