1

This is my js code.

I am using the latest jQuery and Backbone libraries.

(function(Tweet) {

    //Tweet.Model = Backbone.Model.extend();

    Tweet.Collection = Backbone.Collection.extend({
        url: function() {

            return "http://search.twitter.com/search.json?q=twitterapi&callback=?";

        },

        parse: function(data) {
            return data.results;
        }
    });

    Tweet.Views.List = Backbone.Layout.extend({
        template: "#list",

        events: {
            "click li": "update"
        },

        update: function(ev) {
            var index = $(ev.target).index();
            var model = this.collection.at(index);

            this.trigger("update", model);
        },

        serialize: function() {
            return { tweets: this.collection };
        }
    });

    Tweet.Views.Detail = Backbone.Layout.extend({
        template: "#detail",

        serialize: function() {
            return { tweet: this.model };
        }
    });
}) (twitter.module("tweet"));

When I run the url http://search.twitter.com/search.json?q=twitterapi&callback=? on my browser, I can see the results.

So I have the connection to twitter.

When I remove the callback=? from the url in my code, I get the Cross Domain error.

So this means that my version of the jQuery and Backbone is updated enough to automatically format my request as a jsonp callback.

But I continuously get a 403 error.

The following is the error as stated by Chrome console in red:

GET http://search.twitter.com/search.json?q=twitterapi&callback=jQuery19107466092116665095_1364193857160&_=1364193857161 403 (Forbidden) 

Please help me to understand if I am doing anything wrong on my end?

UPDATE

I have tried the following based on some of the suggestions.

I added this https://github.com/jacebeleren/backbonelayoutmanager/commit/6af9a367cea5bcf460b67319137d6f077b1ff5ec

..and this https://github.com/jacebeleren/backbonelayoutmanager/commit/01cfba1c416673617591b0c936e41a27b93bbf51

but the error persists.

UPDATE 2

These are the request headers that I get for the 403 error.

Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Cookie:pid=v3:1364189785315637597538615; guest_id=v1%3A136419139351112726; k=10.35.60.125.1364192963733514; __utma=43838368.881187358.1364192967.1364192967.1364192967.1; __utmc=43838368; __utmz=43838368.1364192967.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); _twitter_sess=BAh7CToPY3JlYXRlZF9hdGwrCKCsPKA9AToMY3NyZl9pZCIlNzc0NjU5ZmQ5%250AN2Q4MjA0M2RjYzQzMjMyZTFjMDk3ZTkiCmZsYXNoSUM6J0FjdGlvbkNvbnRy%250Ab2xsZXI6OkZsYXNoOjpGbGFzaEhhc2h7AAY6CkB1c2VkewA6B2lkIiUxZTc3%250AMTFiNjcwN2M0OWM0OTVmMDA0ODgxNTQ1MzdkZA%253D%253D--43c3e3ef6a53296eb8f6640c3e9dc21539f18ef6
Host:search.twitter.com
Referer:http://bblm.localhost/
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22
Oppoin
  • 36
  • 6
  • i can only guess what the twitter module does, maybe it creates credentials which are sent with the request? inspect the network tab and look exactly which headers are sent and post the raw get request here – pfried Mar 25 '13 at 07:08
  • I have put up the request headers. Please let me know if I need to do anything else. Thanks – Oppoin Mar 26 '13 at 03:40
  • Can you try to delete that Cookie and do the request again? – pfried Mar 26 '13 at 06:53
  • I've cleared my cache and deleted all my cookies, but still same problem. – Oppoin Mar 27 '13 at 06:13
  • facing the same error. it seems they are tracking ip or something like that, because it runs fine on my colleagues pc's. Dont understand why they are doing that – Mandeep Jain Mar 28 '13 at 14:52

1 Answers1

0

Backbone will not automatically format your request for JSONp calls. You'll need to send the { dataType: "jsonp" } in your fetch call for jQuery to format it.

See this : https://stackoverflow.com/a/9996420/340266

Community
  • 1
  • 1
neebz
  • 11,465
  • 7
  • 47
  • 64
  • I did this. Didn't work. https://github.com/jacebeleren/backbonelayoutmanager/commit/01cfba1c416673617591b0c936e41a27b93bbf51 – Oppoin Mar 26 '13 at 03:35
  • nEEbz could you let us know if you anymore ideas? Thanks – Oppoin Mar 27 '13 at 06:16
  • 1
    I've just cloned your repo and it works fine. the `tweets` object get populated on success callback. – neebz Mar 27 '13 at 15:16