0

我是 PHP 和 twillio 的新手。我正在尝试获取我的子帐户的所有类型使用信息。基本上我想将此信息存储在我的谷歌表中并需要此值 在此处输入图像描述

我能够获取我所有的子帐户 SID,如下所示

<?php
require_once 'vendor/autoload.php';

use Twilio\Rest\Client;
$sid  = "my main account sid";
$token = "my token";

$twilio = new Client($sid, $token);

$accounts = $twilio->api->v2010->accounts
                               ->read([], 20);

$items = array();
foreach ($accounts as $record) {
    $items[] = $record->sid;
   
}
 print_r($items);
?>

这可以。我可以在 forsearch 中循环我的所有子帐户以获取使用。对于 Fetch 用法,我正在遵循本指南

代码如下

<?php
require_once 'vendor/autoload.php';

use Twilio\Rest\Client;
$sid  = "my main account";
$token = "my token";

$client = new Client($sid, $token);

$records = $client->usage->records->read(
    array(
        "category" => "sms-outbound",
        "startDate" => "2021-02-01",
        "endDate" => "2021-02-28"
    )
);

// Loop over the list of records and echo a property for each one
foreach ($records as $record) {
    echo $record->price;
}
?>

目前我正在获得我的主要账户的成本。

我不知道如何获得我在上图中提到的不同类型使用的子帐户的成本。我不知道我是否遵循正确的 API 指南来实现我的目标。让我知道这里是否有人可以指导我或举个例子。

非常感谢!

4

1 回答 1

0

Twilio developer evangelist here.

The issue is that you are making the API request on behalf of your main account, so you get the data from that account. To make a request on behalf of a subaccount, you should add the subaccount SID to the API client, like this:

$sid = "main account sid";
$subaccountSid = "subaccount sid";
$token = "main account token";
$client = new Client($sid, $token, $subaccountSid);

Then, when you make requests using this $client they will be made against the subaccount.

于 2021-03-02T01:33:16.323 回答