Android Yelp v2 API with SignPost oauth libs says signature is invalid

Trying to call from android client using oauth libs pointer. I created new APIv2 keys, but didn't seem to make any difference. The error I am getting is as follows:

{"error":{"text":"Signature was 
invalid","id":"INVALID_SIGNATURE","description":"Invalid signature. 
Expected signature base string: GET&http%3A%2F%2Fapi.yelp.com 
%2Fv2%2Fsearch&category_filter%3Drestaurants%2520food%26limit%3D10%26ll 
%3D37.422005%252C-122.084095%26oauth_consumer_key 
%3DPbSjw9p08To_XXXXXXXXZg%26oauth_nonce 
%3D-81097XXXXXXXX560239%26oauth_signature_method%3DHMAC- 
SHA1%26oauth_timestamp%3D129XXXX091%26oauth_token 
%3DARfbDXXXXXXXXlBHARTgygLkcMw9h8eW%26oauth_version%3D1.0%26offset 
%3D0%26radius_filter%3D300%26sort%3D0"}} 

I checked twice, and all my tokens and secret values ​​exactly match that on the API control screen. The code now looks like this:

if (location != null) { 
        String lat = Double.toString(location.getLatitude()); 
        String lng = Double.toString(location.getLongitude()); 
        String category = "restaurants+food"; 
        String radius = "300"; 
        String limit = "10"; 
        String offset = "0"; 
        String sort = "0"; 
        try { 
                String query = String.format("http://api.yelp.com/v2/search?ll=%s, 
%s&category_filter=%s&radius_filter=%s&limit=%s&offset=%s&sort=%s", 
                                URLEncoder.encode(lat, ENCODING_SCHEME), 
                                URLEncoder.encode(lng, ENCODING_SCHEME), 
                                category, 
                                URLEncoder.encode(radius, ENCODING_SCHEME), 
                                URLEncoder.encode(limit, ENCODING_SCHEME), 
                                URLEncoder.encode(offset, ENCODING_SCHEME), 
                                URLEncoder.encode(sort, ENCODING_SCHEME)); 
                OAuthConsumer consumer = new CommonsHttpOAuthConsumer(CONSUMER_KEY, 
CONSUMER_SECRET); 
                consumer.setTokenWithSecret(TOKEN, TOKEN_SECRET); 
                consumer.setMessageSigner(new HmacSha1MessageSigner()); 
                consumer.setSendEmptyTokens(true); 
                consumer.setSigningStrategy(new QueryStringSigningStrategy()); 
                String signedQuery = consumer.sign(query); 
                Log.i(getClass().getName(), signedQuery); 
                HttpGet request = new HttpGet(signedQuery); 
                HttpClient httpClient = new DefaultHttpClient(); 
                HttpResponse response = (HttpResponse) httpClient.execute(request); 
                HttpEntity entity = response.getEntity(); 
                String jsonResult = EntityUtils.toString(entity); 
                Log.i(getClass().getName(), jsonResult); 
+3
source share
1 answer

Just found a problem. You must add a MessageSigner BEFORE configuring TokenSecret, otherwise it is null and everything will be poorly signed

+2
source

Source: https://habr.com/ru/post/1786548/


All Articles