【问题标题】:Twilio: Rest API - Send Message - How to get message sid?Twilio:Rest API - 发送消息 - 如何获取消息 sid?
【发布时间】:2017-03-24 13:04:28
【问题描述】:

我想使用Twilio REST API 发送彩信。消息发送成功但是,我无法获得发送消息的唯一MessageSid

我已经尝试过$result->sid$result->messageSid

当前代码

$result= $client->account->messages->create(
    $to, array('from' => $from,
               'body' => $message,
               'mediaUrl' => $mediaurl
              ));               

if (isset($result->messageSid))
    return $result->messageSid;
else
    return "";

是不是我做错了什么?

【问题讨论】:

  • 您遇到任何错误?
  • 未收到错误。
  • 如果消息发送成功,您是否检查了您的 Twilio 帐户?
  • 尝试打印您的$result 变量,如print_r($result) 并检查您得到的响应。同时检查this 一次。 .

标签: twilio twilio-php twilio-api


【解决方案1】:

这里是 Twilio 开发者宣传员。

如果您检查first code sample on the documentation page for sending messages with Twilio 的输出,您将看到返回的JSON 应该具有sid 属性。像这样:

{
  "sid": "MMc781610ec0b3400c9e0cab8e757da937",
  "date_created": "Mon, 19 Oct 2015 07:07:03 +0000",
  "date_updated": "Mon, 19 Oct 2015 07:07:03 +0000",
  "date_sent": null,
  "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "to": "+15558675309",
  "from": "+15017250604",
  "body": "This is the ship that made the Kessel Run in fourteen parsecs?",
  "status": "queued",
  "num_segments": "1",
  "num_media": "1",
  "direction": "outbound-api",
  "api_version": "2010-04-01",
  "price": null,
  "price_unit": "USD",
  "error_code": null,
  "error_message": null,
  "uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/MMc781610ec0b3400c9e0cab8e757da937.json",
  "subresource_uris": {
    "media": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/MMc781610ec0b3400c9e0cab8e757da937/Media.json"
  }
}

我只是使用了与您类似的代码(我没有发送媒体 URL)并且可以回显$result->sid

$result = $client->account->messages->create(
    'MY_NUMBER',
    array(
        'from' => 'MY_TWILIO_NUMBER',
        'body' => "Hey Jenny! Good luck on the bar exam!"
    )
);

echo $result->sid;

如果有帮助,请告诉我。

【讨论】:

  • 我得到的结果类似于对象(Twilio\Rest\Api\V2010\Account\MessageInstance){....}。有关系吗?
  • 您应该可以在该对象上调用->sid
猜你喜欢
  • 2016-05-29
  • 1970-01-01
  • 1970-01-01
  • 2021-05-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-14
  • 1970-01-01
相关资源
最近更新 更多