简体   繁体   English

适用于Yelp API的Javascript OAuth

[英]Javascript OAuth for Yelp API

I'm trying to retrieve information from the Yelp API for an HTML5/Javascript phone app I'm writing. 我正在尝试从Yelp API中检索正在编写的HTML5 / Javascript电话应用程序的信息。 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\&http%3A%2F%2Fapi.yelp.com%2Fv2%2Fsearch\&_%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" }}) / ** / cb({“ error”:{“ text”:“签名无效”,“ id”:“ INVALID_SIGNATURE”,“ description”:“无效签名。期望的签名基本字符串: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%3 %%%% 3 %% 3D %% 3D%3D%3D%D%D3D %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. 我在jsfiddle中使用了相同的代码,并填写了我的OAuth详细信息,并获得了包含20个位置的数组的完美响应。 So authentication from the web works but from the phone does not, given the same credentials. 因此,在给定相同凭据的情况下,可以通过Web进行身份验证,但不能通过电话进行身份验证。 I suspect it may have something to do with the callback. 我怀疑这可能与回调有关。

The project is written uses Apache Cordova through the Intel XDK ide. 该项目是通过Intel XDK ide使用Apache Cordova编写的。 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. 可以在线运行但不能在手机上运行的脚本可以在http://jsfiddle.net/93YKC/上找到,但实际上只是我在自己的踪迹中找到的一个在线论坛中的示例。

       $.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. 在考虑实现Restful API以便从Yelp获取信息并将其传递给我的应用程序时,我非常乐于接受建议。 This really isn't the way I'd like to get around this and would most likely contravene Yelp's fine print. 这确实不是我想要解决的方法,并且很可能会违反Yelp的优良规定。

Stephen 史提芬

You should try this library. 您应该尝试此库。 It signs your request correctly. 它正确签署了您的请求。 https://github.com/ddo/oauth-1.0a https://github.com/ddo/oauth-1.0a

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM