2

I am having difficulty returning any JSON from the Twitter API. All I want to do is get my Twitter feed as JSON, and have tried to do it like this:

$(document).ready(function(){

    $.ajax({
        url: 'https://api.twitter.com/1.1/user_timeline/johnrobertpett.json',
        dataType: 'jsonp',
        success: function() {
            console.log(data);
        }
    });

});
JohnRobertPett
  • 1,133
  • 4
  • 21
  • 36

3 Answers3

3

The resource URL you have used for fetching user feeds is in incorrect format. It should be as follows : https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=johnrobertpett.json

Please refer the documentation https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline

Hamid Narikkoden
  • 851
  • 5
  • 12
2

You can use oauth.io to do the client side calls to the twitter api:

OAuth.initialize('...oauth.io public key...');
OAuth.popup('twitter', function (err, res) {
    res.get({
        url: '/1.1/statuses/home_timeline.json',
        success: function(data) {
            // data contains the tweets
        }
    );
});

You can see the full example displaying the home timeline: http://jsfiddle.net/KxCs2/1/

(the .get has the same syntax than the $.ajax, so you can use either the success callback or deferred .done as in the example...)

bumpmann
  • 685
  • 1
  • 5
  • 17
1

You did not mention how you resolved the back-end side. With API 1.1 you need to have a new application on Twitter-Dev. And then on the serverside, you must send your authentication info to get your JSON. If you haven't yet, please see following posts:

FOR C# Using Twitter OAuth via API 1.1 without 3rd Party Library

For PHP Simplest PHP example for retrieving user_timeline with Twitter API version 1.1 This answer will help you.

Community
  • 1
  • 1