is it possible to make a system SMS Based Query in Java - java

is it possible to make a system SMS Based Query in Java?because im planning to try and make a System Based on java that has SMS Based query like when you send some sort of code to the system it replies also with a sms

Yes, check out twilio. Pretty great and can set up a cool chat bot type of thing either using some web server or amazon lambda. You can set a script so it will take certain inputs, do whatever code you want and send an output.
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Message;
import com.twilio.type.PhoneNumber;
import java.net.URISyntaxException;
public class SmsSender {
// Find your Account Sid and Auth Token at twilio.com/console
public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
public static final String AUTH_TOKEN = "your_auth_token";
public static void main(String[] args) throws URISyntaxException {
Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
Message message = Message
.creator(new PhoneNumber("+14159352345"), // to
new PhoneNumber("+14158141829"), // from
"Where's Wallace?")
.create();
}
}

Related

Using fallback sync URL in SymmetricDS with Java Extension

I have a situation where I have a mobile system that when it's on the road in will connect to symmetricDS via the default sync URL specified in the engines file. But when that device is back at home base, it ends up on the same internal network as the master symmetricDS server. So it cannot resolve the outside hostname from inside the network.
Anyway.... I want to setup an symmetricDS extension so that it can try the default URL and then fallback to a secondary IP of 192.168.0.5 if it doesn't work. This is the code snippet that I think I need to start with. I have never done any java, so I'm a little lost reading this.
import java.net.URI;
import org.jumpmind.symmetric.ISymmetricEngine;
import org.jumpmind.symmetric.transport.ISyncUrlExtension;
import org.jumpmind.symmetric.ext.ISymmetricEngineAware;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SyncUrlRewrite implements ISymmetricEngineAware, ISyncUrlExtension {
protected Logger log = LoggerFactory.getLogger(getClass());
ISymmetricEngine engine;
#Override
public String resolveUrl(URI url) {
return url.toString();
}
#Override
public void setSymmetricEngine(ISymmetricEngine engine) {
this.engine = engine;
}
}
You might try looking at and implementing the ISyncUrlExtension interface with the resolveUrl() method. To get it to work, configure the sync_url for a node with the protocol of ext://beanName. beanName is the name you give your extension point in the extension xml file.
Then, you can implement logic to have the resolveUrl() method parse, for example, a list of URLs for your mobile client to try in the sync_url string.
public String resolveUrl(URI uri) {
if (uri.toString().startsWith("ext")) {
Map<String, String> params = getParameters(uri);
//Do some logic with your parsed parameters and return a url
} else {
else return uri.toString();
}
}
The HttpBandwidthSelector class can give you an example implementation.

Geolocalization with Bing and Java

Can I use the Bing Maps API with Java for geolocation? I have the API key but I can't find anything on the net.
I've found a method with an Excel Macro that works but isn't enough, I need a java console script to do it.
Cheers, Damiano.
There doesn't appear to be any official way to make use of the Maps API in Java.
However, there is an unofficial Java wrapper for the API located here. This hasn't been updated in a while, so there's no guarantee it will still work, but it should be a good starting point for implementing geocoding requests.
There is also a method for implementing reverse-geocoding requests in the same wrapper at client.reverseGeocode().
import net.virtualearth.dev.webservices.v1.common.GeocodeResult;
import net.virtualearth.dev.webservices.v1.geocode.GeocodeRequest;
import net.virtualearth.dev.webservices.v1.geocode.GeocodeResponse;
import com.google.code.bing.webservices.client.BingMapsWebServicesClientFactory;
import com.google.code.bing.webservices.client.geocode.BingMapsGeocodeServiceClient;
import com.google.code.bing.webservices.client.geocode.BingMapsGeocodeServiceClient.GeocodeRequestBuilder;
public class BingMapsGeocodeServiceSample {
public static void main(String[] args) throws Exception {
BingMapsWebServicesClientFactory factory = BingMapsWebServicesClientFactory.newInstance();
BingMapsGeocodeServiceClient client = factory.createGeocodeServiceClient();
GeocodeResponse response = client.geocode(createGeocodeRequest(client));
printResponse(response);
}
private static void printResponse(GeocodeResponse response) {
for (GeocodeResult result : response.getResults().getGeocodeResult()) {
System.out.println(result.getDisplayName());
}
}
private static GeocodeRequest createGeocodeRequest(BingMapsGeocodeServiceClient client) {
GeocodeRequestBuilder builder = client.newGeocodeRequestBuilder();
builder.withCredentials("xxxxxx", null);
builder.withQuery("1 Microsoft Way, Redmond, WA");
// builder.withOptionsFilter(Confidence.HIGH);
return builder.getResult();
}
}

Google Translate from Java Application

I am trying to do a simple translator by NetBeans. Firstly, I tried to implement the code below from a forum page:(https://www.java-forums.org/java-applets/38563-language-translation.html)
import com.google.api.translate.Language;
import com.google.api.translate.Translate;
public class Main {
public static void main(String[] args) throws Exception {
// Set the HTTP referrer to your website address.
Translate.setHttpReferrer("http://code.google.com/p/google-api-translate-java");
String translatedText = Translate.execute("Bonjour monde le",
Language.FRENCH, Language.ENGLISH);
System.out.println(translatedText);
}
}
I cannot compile the code. I got cannot resolve symbol for setHttpReferrer() although I added related jar.
Secondly, I tried to implement another solution from the page (https://www.java-forums.org/java-applets/61655-language-translation-using-google-api.html). I got my API key and set it.
import com.google.api.GoogleAPI;
import com.google.api.translate.Language;
import com.google.api.translate.Translate;
public class Translation
{
public static void main(String[] args) throws Exception {
GoogleAPI.setHttpReferrer("http://code.google.com/p/google-api-translate-java");
GoogleAPI.setKey("i have set my Api key");
String translatedText = Translate.DEFAULT.execute("Bonjour le monde", Language.FRENCH, Language.ENGLISH);
System.out.println(translatedText);
}
}
When I try to run this I got 403 error as null. Is there a simple way to call Google Translator from Java application?
403 error is documented on the faq as "exceeding your quota". https://cloud.google.com/translate/faq
I suspect however, you get the error because you haven't initialised the API properly, i.e authenticated, ...
Have a look at the setup in this code. Also search for hello welt.
https://github.com/GoogleCloudPlatform/google-cloud-java/blob/master/google-cloud-translate/src/test/java/com/google/cloud/translate/TranslateImplTest.java
Hope this helps.

Sending SMS with java application

Good evening my colleagues I hope you are well please I need to integrate an api that will help me to send SMS and CALL from my java application I have to find one called Ozeki Java SMS SDK but I can not integrate it to my app please if someone can help me find a solution and thanks in advance :)
You can check this one: https://www.twilio.com/docs/quickstart/java/sms
It's not really difficult to use.
Here's the official example given to create a class SmsSender:
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Message;
import com.twilio.type.PhoneNumber;
import java.net.URISyntaxException;
public class SmsSender {
// Find your Account Sid and Auth Token at twilio.com/console
public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
public static final String AUTH_TOKEN = "your_auth_token";
public static void main(String[] args) throws URISyntaxException {
Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
Message message = Message
.creator(new PhoneNumber("+14159352345"), // to
new PhoneNumber("+14158141829"), // from
"Where's Wallace?")
.create();
}
}
Please note that you need to register in order to have an account token.

how is jtwitter OAuth switching?

Here is my code:
import winterwell.jtwitter.Twitter;
import winterwell.jtwitter.*;
import java.util.List;
public class twitterbagla {
private static final String username="blabla";
private static final String password="xx";
public static void main(String[] args) {
Twitter twitter=new Twitter (username,password);
System.out.println(twitter.getStatus("hah"));
//System.out.println(twitter.getFollowers());
twitter.setStatus("hello world something");
List<User> followers=twitter.getFollowers();
for(User user : followers){
System.out.println(user.getName());
}
}
}
and here is console
It's amazing to me that the best things in life are steps forward that come with negative assumptions.
Exception in thread "main" winterwell.jtwitter.TwitterException$UpdateToOAuth: You need to switch to OAuth. Twitter no longer support basic authentication.
at winterwell.jtwitter.URLConnectionHttpClient.processError(URLConnectionHttpClient.java:369)
at winterwell.jtwitter.URLConnectionHttpClient.post2(URLConnectionHttpClient.java:303)
at winterwell.jtwitter.URLConnectionHttpClient.post(URLConnectionHttpClient.java:272)
at winterwell.jtwitter.Twitter.updateStatus(Twitter.java:2593)
at winterwell.jtwitter.Twitter.updateStatus(Twitter.java:2519)
at winterwell.jtwitter.Twitter.setStatus(Twitter.java:2291)
at twitterbagla.main(twitterbagla.java:16)
https://dev.twitter.com/docs/twitter-libraries#java You can find some libraries here..
See the documentation at http://www.winterwell.com/software/jtwitter.php
You want to create an OAuthSignpostClient. There's then an authorisation step with Twitter (you can store the resulting tokens to reuse later).
Then use new Twitter(name, oauthClient) to create your Twitter instance.

Categories