如何使用React Native向Twilio发送短信(SMS)?

时间:2018-06-07 11:14:15

标签: react-native twilio twilio-api

如何使用 Twilio 发送带有原生反应的短信?

我使用此代码但不起作用:

fetch('https://api.twilio.com/2010-04-01/Accounts/ACxxxxxxxxxxx/Messages',
{
        method: 'POST',
        headers: {
            Accept: 'application/json',
            'Content-Type': 'application/json',
                },


            body: JSON.stringify({
                  user:'ACxxxxxxxxxxxxxxxxxxxxxxx',
                  password:'f8xxxxxxxxxxxxxxxxxxxxxx',
                  to: '+3933850xxxx',
                  body: 'test',
                  from: '+3933850xxxx',

                   }),
                });

还有其他方法吗?

1 个答案:

答案 0 :(得分:0)

使用 twilio API

发送消息的示例代码

示例代码

const twilioClient = context.getTwilioClient();
 twilioClient.messages
   .create({ from: context.PHONE_NUMBER, to: phoneNumber, body: message })
   .then(x => {
     // If the SMS was successfully sent, remove the item from the list
     return twilioClient.sync
       .services(event.ServiceSid)
       .syncLists(event.ListUniqueName)
       .syncListItems(orderNumber)
       .remove();
   })