带Android的OAuth

带Android的OAuth,android,oauth,signpost,yelp,Android,Oauth,Signpost,Yelp,我正在尝试访问YelpAPI。我已经拿到了我的钥匙,读了大约40篇文章解释了我需要做什么,我已经尝试了一切。密钥和无效的内容无效。我得到以下信息: 05-16 17:39:54.955: E/AndroidRuntime(538): java.lang.NoClassDefFoundError: oauth.signpost.commonshttp.CommonsHttpOAuthConsumer 我已经导入了commons-codec-1.6jar、signpost-commonshttp4

我正在尝试访问YelpAPI。我已经拿到了我的钥匙,读了大约40篇文章解释了我需要做什么,我已经尝试了一切。密钥和无效的内容无效。我得到以下信息:

05-16 17:39:54.955: E/AndroidRuntime(538): java.lang.NoClassDefFoundError: oauth.signpost.commonshttp.CommonsHttpOAuthConsumer
我已经导入了commons-codec-1.6jar、signpost-commonshttp4-1.2.1.2.jar和signpost-core-1.2.1.2.jar

我仍然收到错误消息。有什么帮助吗

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;


/**
 * Example for accessing the Yelp API.
 */
public class Yelp {
  private String consumerKey = "";
  private String consumerSecret = "";
  private String token = "";
  private String tokenSecret = "";

  /**
   * Search with term and location.
   *
   * @param term Search term
   * @param latitude Latitude
   * @param longitude Longitude
   * @return JSON string response
   */
  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;
  }
}
导入java.net.HttpURLConnection;
导入java.net.URL;
导入java.util.HashMap;
导入java.util.Map;
导入oauth.signpost.oauth;
导入oauth.signpost.OAuthConsumer;
导入oauth.signpost.commonHTTP.commonHttpOAuthConsumer;
导入oauth.signpost.exception.OAuthCommunicationException;
导入oauth.signpost.exception.OAutheExpectationFailedException;
导入oauth.signpost.exception.oauthmessagesignereexception;
/**
*访问YelpAPI的示例。
*/
公开课叫喊{
私有字符串consumerKey=“”;
私有字符串consumerSecret=“”;
私有字符串令牌=”;
私有字符串tokenSecret=“”;
/**
*使用术语和位置进行搜索。
*
*@param术语搜索术语
*@param纬度
*@param经度
*@return-JSON字符串响应
*/
公共字符串搜索(字符串项、双纬度、双经度)抛出OAuthMessageSignerException、OAuthExpectationFailedException、OAuthCommunicationException{
试一试{
OAuthConsumer myConsumer=新的CommonHttpOAuthConsumer(consumerKey,ConsumerCret);
myConsumer.setTokenWithSecret(token,tokenSecret);
字符串urlToPost=”http://api.yelp.com/v2/search";
Map myMap=newhashmap();
myMap.put(OAuth.OAuth_CONSUMER_KEY,consumerKey);
myMap.put(OAuth.OAuth_令牌,令牌);
myMap.put(OAuth.OAuth_签名_方法,“HMAC-SHA1”);
myMap.put(OAuth.OAuth_签名,tokenSecret);
put(OAuth.OAuth_时间戳,Long.toString(System.currentTimeMillis()/1000L));
myMap.put(OAuth.OAuth_NONCE,“asdf”);
urlToPost=OAuth.addQueryParameters(urlToPost,myMap);
HttpURLConnection myCon=(HttpURLConnection)(新URL(urlToPost)).openConnection();
支原体标志(myCon);
myCon.connect();
返回myCon.getResponseMessage();
}捕获(例外e){
e、 printStackTrace();
}
返回null;
}
}

转到项目->属性,在Java构建路径->订单和导出选项卡下,确保选中了这些JAR


而且,仅供将来参考,如果这些是您真正的钥匙,我会确保不会将它们放在公共网站上。只是说说而已。

我在Android应用程序中也面临同样的问题。当我使用signpost-core-1.2.1.2时,它无法解析CommonHttpOAuthConsumer。我从网上下载

成功了