I am trying to access the Yelp API. I got my keys and read about 40 articles explaining what I need to do, and I tried everything. The key is that which is not valid. I get the following:
05-16 17:39:54.955: E/AndroidRuntime(538): java.lang.NoClassDefFoundError: oauth.signpost.commonshttp.CommonsHttpOAuthConsumer
I imported the jar commons-codec-1.6, signpost-commonshttp4-1.2.1.2.jar and signpost-core-1.2.1.2.jar.
I am still getting the error message. Any help?
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import oauth.signpost.OAuth;
import oauth.signpost.OAuthConsumer;
import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer;
import oauth.signpost.exception.OAuthCommunicationException;
import oauth.signpost.exception.OAuthExpectationFailedException;
import oauth.signpost.exception.OAuthMessageSignerException;
public class Yelp {
private String consumerKey = "";
private String consumerSecret = "";
private String token = "";
private String tokenSecret = "";
public String search(String term, double latitude, double longitude) throws OAuthMessageSignerException, OAuthExpectationFailedException, OAuthCommunicationException {
try {
OAuthConsumer myConsumer = new CommonsHttpOAuthConsumer(consumerKey, consumerSecret);
myConsumer.setTokenWithSecret(token, tokenSecret);
String urlToPost = "http://api.yelp.com/v2/search";
Map<String, String> myMap = new HashMap<String, String>();
myMap.put(OAuth.OAUTH_CONSUMER_KEY, consumerKey);
myMap.put(OAuth.OAUTH_TOKEN, token);
myMap.put(OAuth.OAUTH_SIGNATURE_METHOD, "HMAC-SHA1");
myMap.put(OAuth.OAUTH_SIGNATURE, tokenSecret);
myMap.put(OAuth.OAUTH_TIMESTAMP, Long.toString(System.currentTimeMillis() / 1000L));
myMap.put(OAuth.OAUTH_NONCE, "asdf");
urlToPost = OAuth.addQueryParameters(urlToPost, myMap);
HttpURLConnection myCon = (HttpURLConnection) (new URL(urlToPost)).openConnection();
myConsumer.sign(myCon);
myCon.connect();
return myCon.getResponseMessage();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
source
share