骨干/ JS:期待通过Ajax调用访问Twilio短信API [英] Backbone/JS: looking to access the Twilio SMS API via an AJAX call

查看:145
本文介绍了骨干/ JS:期待通过Ajax调用访问Twilio短信API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

寻求建立Twilio的短信服务,这样,当用户presses一定的按钮,它利用与Twilio我的帐户发送一个文本。

Looking to set up Twilio's SMS service so that when a user presses a certain button, it leverages my account with Twilio to send a text.

使用Backbone.js的用的CoffeeScript,这必须要在客户端完成的时刻,所以我做这样的事情:

Using Backbone.js with coffeescript, and this has to be done client-side for the moment, so I'm doing something like this:

events: {
        "click .button": "sendText"
}

然后 sendText 是这样的:

sendText: ()->
    accountSid = '{my account sid}'
    authToken = '{my auth token}'
    ToNumber = "{string of a number to text to}"
    FromNumber = "{string of my Twilio number}"
    Body = escape("Hey, this is working.")

    myJSONData = "To=%2B1" + ToNumber + ", From=%2B1" + FromNumber + ", Body=" + Body

    $.ajax({
                type: 'POST',
                url: 'https://api.twilio.com/2010-04-01/Accounts/'+ accountSid + '/SMS/Messages',
                data: myJSONData,
                success: (data) -> {
                    console.log('SMS sent successfully!')
                }
        })

这是朝着正确的方向吗?我知道,我还没有进入我的身份验证凭据的任何地方还没有,但我不能确定在哪里做呢。

Is this heading in the right direction? I know that I haven't entered my auth credentials anywhere yet, but I'm not certain where to do that yet.

推荐答案

您不应该在任何情况下,有你的authToken(而且情况更糟,因为你还包括您的帐户SID)提供的人谁愿意就看你的源$ C ​​$ C。

You shouldn't, under any circumstance, have your authToken (and the situation is worse as you're also including your account sid) available for anyone who wants to see you source code.

使用这些信息,我可以提供数以您的名义,拨打电话,返回号码...你刚才的不能做在客户端。

With that info, I can provision numbers on your behalf, make calls, return numbers... You just can't do it on the client side.

您应该连接(使用Ajax如果你想)到您的服务器,从而将连接到twilio传递您的凭据。这样一来,谁知道他们只有一个,就是你的服务器。

You should connect (using Ajax if you want) to your server, which in turn would connect to twilio passing your credentials. That way, the only one who knows them is your server.

这篇关于骨干/ JS:期待通过Ajax调用访问Twilio短信API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆