本文整理汇总了Java中com.twilio.http.TwilioRestClient类的典型用法代码示例。如果您正苦于以下问题:Java TwilioRestClient类的具体用法?Java TwilioRestClient怎么用?Java TwilioRestClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TwilioRestClient类属于com.twilio.http包,在下文中一共展示了TwilioRestClient类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.twilio.http.TwilioRestClient; //导入依赖的package包/类
public static void main(String args[]) {
// Initialize the client
Twilio.init(API_KEY_SID, API_KEY_SECRET);
String recordingSid = "RTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
TwilioRestClient restClient = Twilio.getRestClient();
Request request = new Request(
HttpMethod.GET,
Domains.VIDEO.toString(),
"/v1/Recordings/" + recordingSid + "/Media/",
restClient.getRegion()
);
Response response = restClient.request(request);
JSONObject json = new JSONObject(response.getStream());
String mediaLocation = json.getString("location");
System.out.println(mediaLocation);
}
示例2: sendMessage
import com.twilio.http.TwilioRestClient; //导入依赖的package包/类
@Override
public void sendMessage(final SMSBridge smsBridgeConfig, final SMSMessage message)
throws MessageGatewayException {
//Based on message id, register call back. so that we get notification from Twilio about message status
String statusCallback = callBackUrl+message.getId() ;
final TwilioRestClient twilioRestClient = this.getRestClient(smsBridgeConfig);
builder.setLength(0);
builder.append(smsBridgeConfig.getCountryCode()) ;
builder.append(message.getMobileNumber()) ;
String mobile = builder.toString() ;
logger.info("Sending SMS to " + mobile + " ...");
MessageCreator creator = new MessageCreator(new PhoneNumber(mobile), new PhoneNumber(smsBridgeConfig.getPhoneNo()) , message.getMessage() ) ;
creator.setStatusCallback(statusCallback) ;
try {
message.setSubmittedOnDate(new Date());
Message twilioMessage = creator.create(twilioRestClient) ;
message.setExternalId(twilioMessage.getSid());
logger.debug("TwilioMessageProvider.sendMessage():"+TwilioStatus.smsStatus(twilioMessage.getStatus()).getValue());
message.setDeliveryStatus(TwilioStatus.smsStatus(twilioMessage.getStatus()).getValue()) ;
if(message.getDeliveryStatus().equals(SmsMessageStatusType.FAILED.getValue())) {
message.setDeliveryErrorMessage(twilioMessage.getErrorMessage());
logger.error("Sending SMS to :"+message.getMobileNumber()+" failed with reason "+twilioMessage.getErrorMessage());
}
}catch (ApiException e) {
logger.error("ApiException while sending message to :"+message.getMobileNumber()+" with reason "+e.getMessage());
message.setDeliveryStatus(SmsMessageStatusType.FAILED.getValue());
message.setDeliveryErrorMessage(e.getMessage());
}
}
示例3: getRestClient
import com.twilio.http.TwilioRestClient; //导入依赖的package包/类
private TwilioRestClient getRestClient(final SMSBridge smsBridge) {
String authorizationKey = encodeBase64(smsBridge) ;
TwilioRestClient client = this.restClients.get(authorizationKey) ;
if(client == null) {
client = this.get(smsBridge) ;
this.restClients.put(authorizationKey, client) ;
}
return client ;
}
示例4: get
import com.twilio.http.TwilioRestClient; //导入依赖的package包/类
TwilioRestClient get(final SMSBridge smsBridgeConfig) {
logger.debug("Creating a new Twilio Client ....");
String providerAccountId = smsBridgeConfig.getConfigValue(MessageGatewayConstants.PROVIDER_ACCOUNT_ID) ;
String providerAuthToken = smsBridgeConfig.getConfigValue(MessageGatewayConstants.PROVIDER_AUTH_TOKEN) ;
final TwilioRestClient client = new TwilioRestClient.Builder(providerAccountId, providerAuthToken).build();
return client;
}