【问题标题】:OAuth Error using Yelp API使用 Yelp API 的 OAuth 错误
【发布时间】:2016-05-18 04:22:25
【问题描述】:

我有一个使用 Yelp 检索评论和联系信息的示例应用。直到本周它都运行良好。

我现在收到此错误: 未捕获的 ReferenceError:未定义 OAuth

function addmarker(lat,lng, id, name, comments){

var yelpcontent = '<h4>' + name + '</h4>';
var phone = '';
var address = '';
var city = '';
var state = '';
var zip = '';
var rating = '';

var terms = name;
var near = 'Indianapolis,IN';
var cll = lat + "," + lng;
var accessor = {
    consumerSecret: auth.consumerSecret,
    tokenSecret: auth.accessTokenSecret
};
parameters = [];
parameters.push(['term', name]);
parameters.push(['location', 'Indianapolis, IN']);
parameters.push(['cll', cll]);
parameters.push(['callback', 'cb']);
parameters.push(['oauth_consumer_key', auth.consumerKey]);
parameters.push(['oauth_consumer_secret', auth.consumerSecret]);
parameters.push(['oauth_token', auth.accessToken]);
parameters.push(['oauth_signature_method', 'HMAC-SHA1']);
var message = {
    'action': 'http://api.yelp.com/v2/search',
    'method': 'GET',
    'parameters': parameters
};
OAuth.setTimestampAndNonce(message);
OAuth.SignatureMethod.sign(message, accessor);
var parameterMap = OAuth.getParameterMap(message.parameters);
parameterMap.oauth_signature = OAuth.percentEncode(parameterMap.oauth_signature)
$.ajax({
    'url': message.action,
    'data': parameterMap,
    'cache': true,
    'dataType': 'jsonp',
    'type' : 'get',
    'timeout': 5000,
    'success': function(data, textStats, XMLHttpRequest) {


        address = data['businesses'][0].location.address;
        city = data['businesses'][0].location.city;
        state = data['businesses'][0].location.state_code;
        zip = data['businesses'][0].location.postal_code;
        phone = data['businesses'][0].display_phone;
        rating = data['businesses'][0].rating_img_url_small;
        yelpcontent = yelpcontent + '<p>' + address + '<br/>' + city + ', ' + state + '  ' + zip + '<br/>' + phone + '</p><p><strong>Yelp Rating</strong></p><p><img src=' + rating + '></p><p><strong>Personal Review</strong></p><p>' + comments + '</p>';

    },
    'error': function(data, textStats, XMLHttpRequest) {
        console.log(name + ' ' + 'did not work');
        console.log(XMLHttpRequest);
        yelpcontent = yelpcontent + '<p>' + comments + '</p>';
    }


});

谁能告诉我我做错了什么?

【问题讨论】:

    标签: javascript oauth yelp


    【解决方案1】:

    Javascript 中默认没有定义 OAuth。

    您必须将其添加到您的页面。

    使用此代码:

        <script type="text/javascript" src="http://oauth.googlecode.com/svn/code/javascript/oauth.js"></script>
        <script type="text/javascript" src="http://oauth.googlecode.com/svn/code/javascript/sha1.js"></script>
    

    你可以看到一个完整的例子here

    【讨论】:

    • 我的 html 文件中有这些,但它仍然无法正常工作。 :(
    • 你能检查一下 1.
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-16
    相关资源
    最近更新 更多