我試圖在我的GWT應用程序中使用Twilio的官方Java庫來發送短信。如何在Google AppEngine中使用GWT的Twilio(Java)
這裏是Twilio代碼,我在我的應用程序中使用:
public class TwilioSMS{
/** The Constant ACCOUNT_SID. */
public static final String ACCOUNT_SID = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
public static final String AUTH_TOKEN = "xxxxxxxxxxxxxxxxxxxxxxxxx";
// Create a rest client
TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
/**
* The main method.
*
* @param args
* the arguments
* @throws TwilioRestException
* the twilio rest exception
*/
public String sendMessage(String _to, String _message) throws TwilioRestException
{
// Get the main account (The one we used to authenticate the client
Account mainAccount = client.getAccount();
// Send an sms
SmsFactory smsFactory = mainAccount.getSmsFactory();
Map<String, String> smsParams = new HashMap<String, String>();
smsParams.put("To", _to); // Replace with a valid phone number
smsParams.put("From", "(646) 755-7665"); // Replace with a valid phone // number in your account
smsParams.put("Body", _message);
smsFactory.create(smsParams);
// Make a raw request to the api.
TwilioRestResponse resp = client.request("/2010-04-01/Accounts", "GET",
null);
if (!resp.isError()) {
return resp.getResponseText();
}
else
{
return "Failed to send the message.";
}
}
}
當我運行在GAE的代碼中,我得到了以下異常:
java.lang.NoClassDefFoundError: javax.net.ssl.KeyManagerFactory is a restricted class. Please see the Google App Engine developer's guide for more details.
我也認識到,有一個gwt-twilio http://code.google.com/p/gwt-twilio/但是這是twilio客戶端的封裝器(它不處理髮送文本消息)
任何使用GAE + GWT中的twilio發送文本消息的示例e有幫助!
感謝
坤
感謝彼得......上面的Twilio類在服務器端,它在一個由GWT-RPC請求調用的方法中。但是,GAE仍在抱怨_java.lang.NoClassDefFoundError:javax.net.ssl.KeyManagerFactory是一個受限制的類。請參閱Google App Engine開發人員指南瞭解更多詳情._ – enfany
Kun,我認爲他意味着您可能必須自己進行HTTP調用,而不使用Twilio客戶端,因爲Twilio客戶端的類不是'在應用引擎上列入白名單。下面是一篇關於如何使用Apache的HttpClient4來解決URL Fetch API限制的文章: http://esxx.blogspot.com/2009/06/using-apaches-httpclient-on-google-app.html –