Link to home
Start Free TrialLog in
Avatar of mike99c
mike99c

asked on

Cannot get Twitter API 1.1 to work

I have been using the Twitter API code below to list some Twitter feeds on a website. Unfortunately Twitter has made some changes which require you to autenticate yourself before you can use the script.

I understand you have to use oAuth to authenticate access to the API.
https://dev.twitter.com/docs/auth/oauth

Unfortunately I cannot understand how to integrate this into the script. Or is this something that has to be done separately?

JQTWEET = {
	
	// Set twitter username, number of tweets & id/class to append tweets
	user: 'twitterscreenname',
	numTweets: 2,
	appendTo: '#jstwitter',

	// core function of jqtweet
	loadTweets: function() {
		$.ajax({
			url: 'https://api.twitter.com/1.1/statuses/user_timeline.json',
			type: 'GET',
			dataType: 'jsonp',
			data: {
				screen_name: JQTWEET.user,
				include_rts: true,
				count: JQTWEET.numTweets,
				include_entities: true
			},
			success: function(data, textStatus, xhr) {

			 var html = '<div class="tweet">TWEET_TEXT';

				 // append tweets into page
				 for (var i = 0; i < data.length; i++) {
					$(JQTWEET.appendTo).append(
						html.replace('TWEET_TEXT', JQTWEET.ify.clean(data[i].text))
							.replace(/USER/g, data[i].user.screen_name)
							.replace('AGO', JQTWEET.timeAgo(data[i].created_at))
							.replace(/ID/g, data[i].id_str)
					);

				 }					
			}	

		});
		
	}, 
	
		
	/**
      * relative time calculator FROM TWITTER
      * @param {string} twitter date string returned from Twitter API
      * @return {string} relative time like "2 minutes ago"
      */
    timeAgo: function(dateString) {

	}, // timeAgo()
    
	
    /**
      * The Twitalinkahashifyer!
      * http://www.dustindiaz.com/basement/ify.html
      * Eg:
      * ify.clean('your tweet text');
      */
    ify:  {

    } // ify

	
};

$(document).ready(function () {
	// start jqtweet!
	JQTWEET.loadTweets();
});

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mike99c
mike99c

ASKER

Thanks for the links but I have seens these before and simply cannot make any sense of them. I was hoping someone could provide actual examples.

Can the authentication be done client side inside the JQuery?
Can the authentication be done client side inside the JQuery?

No,
If you ask this a second time it look like you don't want to accept the new rules

That's why you see server side code each time you try to find an answer to your question