4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

twilioの1架電ごとの料金一覧出力

Last updated at Posted at 2016-09-03

twilioで架電した際、1架電の料金を知りたい際に参考にしてください。

##環境構築

まずはいつものcomposer揃えるところから。
環境ある人は飛ばしちゃってください。

curl -sS https://getcomposer.org/installer | php
php composer.phar require twilio/sdk

##サンプルPHPコード
今回は架電先の電話番号を条件に指定して、
通話時間と料金を出力してみました。

cost.php
<?php
require __DIR__ . '/vendor/autoload.php';

use Twilio\Rest\Client;

$sid = '自分のSID';
$token = '自分のtoken';
$client = new Client($sid, $token);

$records = $client->calls->read(
  array(
    "to" => "条件に指定したい電話番号"
  )
);
foreach ($records as $record) {
    echo "通話時間: " . $record->duration ."<br>";
    echo "料金: " . substr($record->price, 1,-1) . "<br>";}

$record->priceは一文字目にハイフンがなぜかくっついてくるのでsubstrしています。

今月分の料金〜とか、他に条件を指定したい場合は
下記ドキュメントをご参考に。

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?