使用Twillio發送短信我下面的代碼使用....但短信不來......在android系統
private void sendSms(String toPhoneNumber, String message){
OkHttpClient client = new OkHttpClient();
String ACCOUNT_SID="XXXXXXXXXXXXXXXXXXXXXXXXXX";
String AUTH_TOKEN="XFAXXXXXXXXXXXXXXXXXXXXXXXXX";
String url = "https://api.twilio.com/2010-04-01/Accounts/"+ACCOUNT_SID+"/SMS/Messages";
String base64EncodedCredentials = "Basic " + Base64.encodeToString((ACCOUNT_SID + ":" + AUTH_TOKEN).getBytes(), Base64.NO_WRAP);
RequestBody body = new FormBody.Builder()
.add("From", "+16463525791")
.add("To", toPhoneNumber)
.add("Body", message)
.build();
Request request = new Request.Builder()
.url(url)
.post(body)
.header("Authorization", base64EncodedCredentials)
.build();
try {
Response response = client.newCall(request).execute();
// Log.d(TAG, "sendSms: "+ response.body().string());
} catch (IOException e) { e.printStackTrace(); }
}
我需要發送短信到用戶註冊之後......請幫助...
這是一個Python腳本....我需要在Android的幫助 –
'ACCOUNT_SID'&'AUTH_TOKEN'是否正確?您的Twilio帳戶中剩餘餘額了嗎?因爲這項服務是付費的。 – Gattsu