Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8936981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:19:45+00:00 2026-06-15T10:19:45+00:00

I’m trying to use backbone for a local project that’s never going to see

  • 0

I’m trying to use backbone for a local project that’s never going to see a real web server, and which interacts with the Yelp API via AJAX. The Yelp API requires we use oauth to authenticate, and gives sample code that I’ve modeled my own code after. When I use the sample code, I don’t run into any problems with Cross-Origin or anything. However, when I turn off my browser security options I just get a 400 response for errors.

I had tried overwriting the fetch method as follows:

fetch: function(options) {
  var accessor, message, parameterMap, parameters;
  if (!options) {
    options = {};
  }
  accessor = {
    consumerSecret: LOAF.auth.conserumerSecret,
    tokenSecret: LOAF.auth.accessTokenSecret
  };
  parameters = [];
  parameters.push(['oauth_consumer_key', LOAF.auth.consumerKey]);
  parameters.push(['oauth_consumer_secret', LOAF.auth.consumerSecret]);
  parameters.push(['oauth_token', LOAF.auth.accessToken]);
  parameters.push(['oauth_signature_method', 'HMAC-SHA1']);
  parameters.push(['location', "New York City"]);
  message = {
    'action': this.url,
    'method': 'GET',
    'parameters': parameters
  };
  OAuth.setTimestampAndNonce(message);
  OAuth.SignatureMethod.sign(message, accessor);
  parameterMap = OAuth.getParameterMap(message.parameters);
  parameterMap.oauth_signature = OAuth.percentEncode(parameterMap.oauth_signature);
  options.url = this.url;
  options.data = parameterMap;
  options.cache = true;
  options.dataType = 'json';
  options.success = this.onResponse;
  console.log("Attempting");
  console.log(options);
  return Backbone.Model.prototype.fetch.apply(this, options);
},

but this generates the 400 response. I have a feeling its because I’m not making the AJAX call properly because backbone does most of it for me and is likely overwriting some of the options I’m setting. I think what I need to do is overwrite this collection’s “sync” method instead to just handle the OAuth and parse the response myself. Is there a better way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:19:47+00:00Added an answer on June 15, 2026 at 10:19 am

    I’m not sure if this is the proper way to do things, but it works this way, so here’s my solution. I override fetch and never call the default fetch method. Instead I make an ajax call in the fetch method, and have an onResponse method that handles the response, creating the models (Yelp Businesses) for the response. Hope this helps anyone in the same position.

    LOAF.YelpList = Backbone.Collection.extend({
      model: LOAF.Business,
      url: 'http://api.yelp.com/v2/search?',
      fetch: function(options) {
        var accessor, message, parameterMap, parameters;
        if (!options) {
          options = {};
        }
        accessor = {
          consumerSecret: LOAF.auth.consumerSecret,
          tokenSecret: LOAF.auth.accessTokenSecret
        };
        parameters = [];
        parameters.push(['callback', 'cb']);
        parameters.push(['oauth_consumer_key', LOAF.auth.consumerKey]);
        parameters.push(['oauth_consumer_secret', LOAF.auth.consumerSecret]);
        parameters.push(['oauth_token', LOAF.auth.accessToken]);
        parameters.push(['oauth_signature_method', 'HMAC-SHA1']);
        parameters.push(['location', "New York City"]);
        message = {
          'action': this.url,
          'method': 'GET',
          'parameters': parameters
        };
        OAuth.setTimestampAndNonce(message);
        OAuth.SignatureMethod.sign(message, accessor);
        parameterMap = OAuth.getParameterMap(message.parameters);
        parameterMap.oauth_signature = OAuth.percentEncode(parameterMap.oauth_signature);
        options.url = this.url;
        options.data = parameterMap;
        options.cache = true;
        options.dataType = 'jsonp';
        options.jsonpCallback = 'cb';
        options.success = this._onResponse;
        options.context = this;
        return $.ajax(options);
      },
      _onResponse: function(data, textStats, xhr) {
        debugger;
        var _this = this;
        return _.each(data.businesses, function(business) {
          var busModel;
          if (!_this.get(business.id)) {
            busModel = new LOAF.Business(business);
            return _this.add(busModel);
          }
        });
      }
    });
    

    Two things to note:

    1. The initial code would have worked but the consumerSecret was spelled wrong, resulting in improper OAuth calls. That’s why I was getting a 400 error.
    2. Even if you fix this, there’s the problem of Cross-Origin calls. Switching to the AJAX method I used alleviates this problem. However, there may exist a way to fix this more native to Backbone. For the time-frame of my project, this would not do.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.