question on dialing out with Twilio引起了我的注意,特别是:
capability.allowClientOutgoing("APf5250942ec073c9d08848990cbc0ff5e");
查看sample code:
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.instance.Application;
public class Example {
// Find your Account Sid and Token at twilio.com/user/account
public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
public static final String AUTH_TOKEN = "your_auth_token";
public static void main(String[] args) throws TwilioRestException {
TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
// Get an object from its sid. If you do not have a sid,
// check out the list resource examples on this page
Application app = client.getAccount().getApplication("AP2a0747eba6abf96b7e3c3ff0b4530f6e");
System.out.println(app.getSmsUrl());
}
}
它不是更清楚。 ACCOUNT_SID
和AUTH_TOKEN
很容易复制/粘贴。我在哪里以及如何获取要发送的字符串?
Javadocs说:
getApplication
public Application getApplication(String sid)
Get a given application instance by sid
Parameters:
sid - The 34 character sid starting with AP
这让我回到了获取SID以发起呼叫的地点和方式。
答案 0 :(得分:4)
要求的应用程序ID是TwiML应用程序ID。这些可以通过浏览器https://www.twilio.com/console/voice/dev-tools/twiml-apps/add手动创建,也可以使用Twilio REST API以编程方式创建,如https://www.twilio.com/docs/api/rest/applications#list-post中所述。
主要是应用程序ID会将2个网址:语音和消息回调网址与您的应用程序相关联。这些是Twilio在获取新事件或需求信息时会尝试发出请求的应用程序URL。这些网址应返回TwiML
答案 1 :(得分:0)
临时SID为in the portal for testing。但是,this kluge executes通过生成具有新SID的新应用:
private void createApplication(TwilioRestClient client, String accountSID, String authToken, String fromNumber, String toNumber) {
log.info("createApplication..");
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("FriendlyName", "Phone Me"));
params.add(new BasicNameValuePair("VoiceUrl", "http://demo.twilio.com/docs/voice.xml"));
params.add(new BasicNameValuePair("VoiceMethod", "GET"));
ApplicationFactory appFactory = client.getAccount().getApplicationFactory();
Application app = null;
try {
app = appFactory.create(params);
} catch (TwilioRestException ex) {
Logger.getLogger(Twilio.class.getName()).log(Level.SEVERE, null, ex);
}
String sid = app.getSid();
log.info(sid);
log.info("name\n" + app.getFriendlyName());
log.info("sms url\n" + app.getSmsUrl());
log.info("voice url\n" + app.getVoiceUrl());
makeCall(client, accountSID, authToken, fromNumber, toNumber, sid);
}