Reputation: 385
I'm trying to retrieve information from the Yelp API for an HTML5/Javascript phone app I'm writing. I've been through quite a number of examples and keep receiving an error message stating:
/**/cb({"error": {"text": "Signature was invalid", "id": "INVALID_SIGNATURE", "description": "Invalid signature. Expected signature base string: GET\u0026http%3A%2F%2Fapi.yelp.com%2Fv2%2Fsearch\u0026_%3D1405603996179%26callback%3Dcb%26location%3DSan%252BFrancisco%26oauth_consumer_key%3DXXX%26oauth_consumer_secret%3DXXX%26oauth_nonce%3DFGmffH%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1405603996%26oauth_token%3DXXX%26term%3Dfood" }})
I've used the same code in a jsfiddle and having filled in my OAuth details get a perfect response with an array of 20 locations. So authentication from the web works but from the phone does not, given the same credentials. I suspect it may have something to do with the callback.
The project is written uses Apache Cordova through the Intel XDK ide. I've tested both in the emulator and on a device to the same end. The script that works online but not on my phone is available at http://jsfiddle.net/93YKC/ but is really just a sample taken from an online forum I found in my trails.
$.ajax({
'url' : message.action,
'data' : parameterMap,
'dataType' : 'jsonp',
'jsonpCallback' : 'cb',
'success' : function(data, textStats, XMLHttpRequest) {
console.log(data);
}
});
I'm very open to suggestions as I'm contemplating implementing a Restful API to get the information from Yelp and pass it on to my app. This really isn't the way I'd like to get around this and would most likely contravene Yelp's fine print.
Stephen
Upvotes: 0
Views: 1647
Reputation: 3077
You should try this library. It signs your request correctly. https://github.com/ddo/oauth-1.0a
Upvotes: 2