如何使用twilio sdk以json格式获得响应

时间:2017-04-19 03:27:03

标签: php twilio twilio-api twilio-php

我正在使用Twilio的PHP SDK发送短信。以下是代码:

<?php
// Required if your environment does not handle autoloading
require './autoload.php';

// Use the REST API Client to make requests to the Twilio REST API
use Twilio\Rest\Client;

// Your Account SID and Auth Token from twilio.com/console
$sid = 'XXXXXXXXXXXXXXXXXXXXXXXX';
$token = 'XXXXXXXXXXXXXXXXXXXX';
$client = new Client($sid, $token);

// Use the client to do fun stuff like send text messages!
$client->messages->create(
    // the number you'd like to send the message to
    '+XXXXXXXXXX',
    array(
        // A Twilio phone number you purchased at twilio.com/console
        'from' => '+XXXXXXXX',
        // the body of the text message you'd like to send
        'body' => 'Hey Jenny! Good luck on the bar exam!'
    )
);

**Response:
[Twilio.Api.V2010.MessageInstance accountSid=XXXXXXXXXXXXXXXX sid=XXXXXXXXXXXXXXX]**

如何以JSON格式获取响应? 任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:1)

快速答案是:

java.awt.event.KeyEvent[unknown type,keyCode=1,keyText=Unknown keyCode: 0x1,keyChar='1',modifiers=Shift,extModifiers=Shift,keyLocation=KEY_LOCATION_UNKNOWN,rawCode=0,primaryLevelUnicode=0,scancode=0,extendedKeyCode=0x0] on textfield0
java.awt.event.KeyEvent[unknown type,keyCode=2,keyText=Unknown keyCode: 0x2,keyChar='2',modifiers=Ctrl,extModifiers=Ctrl,keyLocation=KEY_LOCATION_UNKNOWN,rawCode=0,primaryLevelUnicode=0,scancode=0,extendedKeyCode=0x0] on textfield1
java.awt.event.KeyEvent[unknown type,keyCode=3,keyText=Cancel,keyChar='3',modifiers=Ctrl+Shift,extModifiers=Ctrl+Shift,keyLocation=KEY_LOCATION_UNKNOWN,rawCode=0,primaryLevelUnicode=0,scancode=0,extendedKeyCode=0x0] on textfield2

使用$json_string = json_encode(</POST|GET>); $_POST super globals,您将获得json字符串格式。

例如

$_GET

通过这种方式,您可以用JSON表示形式对值进行编码。