简体   繁体   English

使用Twilio在C#中发送短信

[英]Sending SMS in C# using Twilio

I read all the other questions regarding this topic but none actually answers exactly my question. 我阅读了有关该主题的所有其他问题,但没有一个能真正回答我的问题。 I installed twilio package. 我安装了twilio软件包。 added it to the C# project. 将其添加到C#项目。 opened an account in twilio and had a number and so on. 在twilio开了一个帐户,并有一个号码,依此类推。 but it seems not working any ideas ? 但是似乎没有任何想法吗? here's the code 这是代码

using System;
using Twilio;

namespace Project_C_Sharp_Final
{
    public partial class User : Form
    {

 private void label4_Click(object sender, EventArgs e)
        {
            string AccountSid = "[i wrote the sid here]";
            string AuthToken = "[i wrote the authtoken here]";
          var twilio = new TwilioRestClient(AccountSid, AuthToken);
          var message = twilio.SendMessage("YOUR_TWILIO_NUMBER", "THE NUMBE I WANT TO SEND TO" , "Check New Offers");
       }
   }
}    

message is not being sent... did i write anything wrong ? 消息未发送...我写错了吗? did i miss anything ? 我想念什么吗?

Before putting my solution, I want to re-iterate what philnash has mentioned. 在提出解决方案之前,我想再次重申philnash提到的内容。 Testing Twilio Credentials will not actually send SMS. 测试Twilio凭据实际上不会发送SMS。

If you are using test credendials then below solution will not work for you. 如果您使用的是测试证书,则以下解决方案对您不起作用。

For error : Permission Not Enable for the region indicated by the to number, that means the country you are trying to send SMS to is not enabled in geolocation settigs of your Twilio account. 对于错误:收件人编号所指示的区域的权限未启用,这意味着Twilio帐户的地理位置设置中未启用您尝试向其发送SMS的国家。

You need to loging to twilio portal and navigate to following URL. 您需要登录到twilio门户并导航到以下URL。 https://www.twilio.com/user/account/settings/international https://www.twilio.com/user/account/settings/international

Here you can enable/disable countries for both SMS and Voice Call. 在这里,您可以启用/禁用短信和语音通话的国家/地区。 Check if the country you are trying to send SMS to is enabled in that page or not. 检查您要向其发送短信的国家/地区是否在该页面中启用。 If not you can enable it and try sending SMS again. 如果没有,您可以启用它,然后尝试再次发送SMS。

Thanks and regards, Chetan Ranpariya 谢谢和问候,Chetan Ranpariya

Twilio developer evangelist here. Twilio开发人员布道者在这里。

In the comments you say you're using the test credentials. 在评论中,您说您正在使用测试凭据。 Test credentials will not actually send any messages (or make calls) they are to make sure you're making the request correctly without costing you. 测试凭据实际上不会发送任何消息(或拨打电话),以确保您正确发出请求而不会花费您。

To make Twilio send messages you need to use the production credentials. 要使Twilio发送消息,您需要使用生产凭据。 If you are still on a trial account this won't cost you anything either. 如果您仍使用试用帐户,则也不会花费任何费用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM