Twitter API 1.1 Guide


Twitter widget is build on Twitter API 1.1 because Twitter disabled API 1.0. Unfortunately Twitter is not that easy now to include on your website, you need to have API keys (similar to Facebook). To get the access keys you need to sign in and create an application on the Twitter Developer Site. Once your application is created Twitter will generate your Oauth settings and access tokens.

 

Step 1: Sign in to Twitter

Sign in to Twitter. If you don’t already have a Twitter account, you can sign up at the Twitter home page to create one.

 
Step 2: Create your Twitter App

After you sign in, you’ll be taken to your application creation page. Be sure to fill in your all fields.

 

Step 3: Authorize your domain

Go to the @Anywhere domains page and add there your domain without "WWW" or "http" prefix e.g. vasterad.com

 

Step 4: Get Access Tokens

Go back to your Twitter app’s detail page and copy following keys:

 

Step 5: Setting up widget

When you have this keys and authorized your domain, open twiter.php and paste them to the correct fields:

// The tokens, keys and secrets from the app you created at https://dev.twitter.com/apps
$config = array(
'oauth_access_token' => 'token-here',
'oauth_access_token_secret' => 'token-here',
'consumer_key' => 'token-here',
'consumer_secret' => 'token-here',
'use_whitelist' => false, // If you want to only allow some requests to use this script.
'base_url' => 'http://api.twitter.com/1.1/'
);

use_whitelist must be set to false

 

Then in HTML files replace current widget script with script below and change nickname to yours. You can also modify count of visible tweets. Keep in mind that you need to upload your site online to make widget works.

<script type="text/javascript">
	jQuery(document).ready(function($){
	$.getJSON('twitter.php?url='+encodeURIComponent('statuses/user_timeline.json?screen_name=Vasterad&count=1'), function(tweets){
		$("#twitter").html(tz_format_twitter(tweets));
	}); });
</script>