Introduction: Twitter Tweets to RSS Feed, Abiding by the Twitter Rules, OAuth, PHP, Apps Engine Are Used

You may have enjoyed the RSS feeds Twitter offered some time ago, but they went away March of 2013. In September of 2012 Twitter unveiled version 1.1 of its API. Twitter now offers up data in the JASON format, and requires you to create an app and register it to get the data, you can't use a 3rd party to do this for you. There are 3rd party apps that spring up and are shut down (like a Whack-a-Mole game)... so in this instructable, I hope to walk you through the process of setting up your own app, and get those tweets flowing again in RSS. This is a very simple system that will allow you to get tweets from one account (any one you pick), you can also set how many tweets are returned from the account (always from the latest tweets down).

We will walk through the whole process: 1. Creating a Gmail account, you will need a phone number that can be associated with the account. 2. Creating a Twitter account, you will need to have your email account so you can verify it. 3. Loading Notepad++, and Python 2.7.X (tools to modify the code, provided, and run the App Engine Launcher), 4. Create an app in Twitter, and an app in Google's App Engine. 5. Information on using Twitter logo to keep your efforts in line with the Twitter T&C's (must be displayed on the page with the Tweets).

I assume you are not a programmer, but know your way around your computer!

So here we go!

Step 1: Get a Google Gmail Account, and Verify It.

First things first, go to www.gmail.com and click on "create an account" at the bottom of the page. Fill out the form, pick your password carefully! Do the captcha and you are good.
Log in to the gmail account and in the upper right you will see your email address, click on the drop down arrow, and select Account (you will see “Privacy” just to the right of the word Account).
Select “Security,” then select in the Account permissions area “Access for less secure apps” setting, Enabled.



Now on to Twitter.

Step 2: Create a Twitter Account.

Go to twitter.com and click on "Sign up for Twitter." Then fill out the form. I unchecked the two boxes at the end, as I didn't want to stay signed in, and I didn't want Twitter to know my browsing habits.

Click "Create My Account"
Now you have to do a little training with Twitter, they want you to add friends and get tweet from celebrities, add a photo etc.

Then you need to check your Gmail account and under the "Social" tab, you will find an email from Twitter, click on it to validate the account.

Step 3: Upload and Install Python 2.7.x Programming Language

Google is a Python shop, meaning their programmers do a lot of development in Python (a great programming language for beginners and pros' alike.

So to use some of their tools, like Apps Engine Launcher, we are going to need to install Python version 2.7.X (the "X" is for whatever version is available).

Go to https://www.python.org/download/

Double Click the Python 2.7.X version (currently 2.7.6) for windows installer, it will download (in Chrome it downloads in the lower left of the browser, Firefox has the green arrow in the upper right of the browser window), if you have a Mac or Linux box, those downloads are further down on the page.

Once it is downloaded, double click on the installer file, and run it. Leave everything in default position, install for all users, and the default install place (C:\Python27\), click next.....

Finish the install and we are ready for the next item.

Step 4: Installing Notepad++ to Edit the Programs

We need to edit some code (you have no worries, we will not be writing code). A great tool to edit code is NotePad++

Go to http://notepad-plus-plus.org/
Click on the download tab, then install it by double clicking on the download, say Yes to the install, hit OK if English is your choice of language, next, agree to T&C's, leave the install on the default location and hit next, leave the default install options (I just had the "create Shortcut on Desktop" selected), hit install. Un-check run now and Finish.

Step 5: Create Your Twitter App, and Get the Codes Needed for the Google App Engine Launcher

While signed in to your Twitter account, open a new browser tab and go to:
https://apps.twitter.com/

Click on create a new app.

Now fill in the form, pick a name for your app (it can be anything), and a description, you must use a full URL for the web site, the only thing you must get exactly right is the call back:

https://spreadsheets.google.com/macros/

The rest is up to you... Now scroll down and agree to the T&C's and create the app.

Now click on the API Keys tab, here we need the API key and API secret. Just leave this web page open, we will come back and cut and paste them into the index.php code (coming up).






Step 6: Creating the Google App Engine App and Getting the Launcher Setup.

Sign in to your Gmail account and go to:
https://appengine.google.com/start/createapp

Not so fast, you may have to connect your phone with your Gmail account, (Google will call you or text you a number, enter it in the box and you are now ready to move forward).

Now fill out the form. Give your Google App a name, possibly the same name you used for the Twitter App, but all in lower case and no spaces. Check Availability, if it isn't used you are good to go, otherwise change the name till you get one to register. You need to remember this URL: yourappname.appsport.com you will get your tweets here soon enough... Finish the form, give your app a Title (I just left the "Open to all" selected). Now agree to the terms and create your app (it is now registered).



Step 7: Get the Code Ready, Add the API Key and Secrets

Here we go (read this, the first paragraph before you do anything), copy and paste the code below into a new NotePad++ file. Do that by clicking in the first line, then shift clicking the last line, to highlight the code (look for the line that says" ---copy everything below this line to the bottom of the page---"), then ctrl+c to copy it all and then open a new file in Notepad++ (All Programs, Notepad++, then click on Notepad++ to open the editor, ctrl+n opens a new file, now ctrl+v to past the code in to a new NotePad++ document. Change the "YOURAPIKEY" and the "YOURAPISECRET" to the API Key and API Secret you got from Twitter. Make sure you don't delete the "." periods at the end of YourAPIKEY and the beginning of YOURAPISECRET.... you have to be very careful, to only add your stuff and not change the program. The area, where you select, will turn green (in notepad++) when you have just the "YOURAPIKEY" selected to paste in your key, replacing YOURAPIKEY with the one you got from Twitter; same with the secret. These are only in the one spot at the top of this file, on line two. The line with php will be the first line in the file. Save the file in a folder and call it main.php


-------copy everything below this line to the bottom of the page-----

<?php
$encodedAccessToken = base64_encode('YOURAPIKEY'.':'.'YOURAPISECRET');    

//Setup the stream context options and create the stream to POST to twitter, added "'" around APIKey and APISecret in case they have a number at the beginning or end


    $options = array(
        'http' => array(
            'method' => 'POST',
            'header' => 'Authorization: Basic '.$encodedAccessToken,
            'content' => 'grant_type=client_credentials',
        ),
    );
    $context  = stream_context_create($options);
    $result = json_decode(@file_get_contents('https://api.twitter.com/oauth2/token', false, $context));
    if(isset($result->token_type) && $result->token_type == 'bearer')
    {
        $twitter_bearer_access_token = $result->access_token;
    }
    else
    {
        //something broke
        $twitter_bearer_access_token = false;
    }
$data = array('screen_name' => $_GET["name"], 'count' => $_GET["count"]);
$data = http_build_query($data);
$context2 =
	array('http'=>
		array(
			'method' => 'GET',
			'header' => 'Authorization: Bearer '.$twitter_bearer_access_token,
	),
	);
$context2 = stream_context_create($context2);
$json = file_get_contents('http://api.twitter.com/1.1/statuses/user_timeline.json?screen_name='.$GET["name"].'&count='.$GET["count"], fasle, $context2);

$return = json_decode($json);

?>


<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><?php echo 'Twitter RSS converter'; ?></title>
		<link><?php echo 'http://www.twitter.com'; ?></link>
	<?php foreach ($return as $line) { ?>
	<item>
		<title><?php echo htmlspecialchars(htmlspecialchars_decode($line->user->name.": ".strip_tags($line->text))); ?></title>
		<user><?php echo htmlspecialchars('@'.$_GET["name"]);?></user>
		<description><?php echo htmlspecialchars(htmlspecialchars_decode(strip_tags($line->text))); ?></description> 
		<guid><?php echo htmlspecialchars("https://twitter.com/".$line->user->screen_name."/statuses/".$line->id_str); ?></guid>
		<link><?php echo htmlspecialchars("https://twitter.com/".$line->user->screen_name."/statuses/".$line->id_str); ?></link>
	</item>
	<?php } ?>
	</channel>
</rss>

Step 8: Download and Install the Google App Engine Launcher

Open the File menu and create a new application. In the popup add a new application, enter the Google App name we created earlier, this could be different from the Twitter App name we used. Enter the Google App name, then browse to the parent directory we save the index.php and app.yaml files in. Next select PHP in the run time drop down menu. Then hit create.

Now you will see the app Google App Launcher, the top and only one... click on it. Now Deploy

Go to: https://developers.google.com/appengine/downloads... Download the Google App engine SDK for PHP (you pick the operating system)

After it downloads, double click on it and install it (everything default).

Launch Google App Engine Launcher. You will need the name of the Google App you created in the app before.

File, Create New Application

Enter the name you created in the Google App Engine step (without the .appspot.com, just the app name)

Browse to the directory you want the code setup in (it will create a sub directory)

Select the Runtime, we are using PHP, Leave the Port and Admin Port unchanged

Click on the Create button

Test the temporary app code

Click on the app name (below) to select it

Click on the run button (big green arrow), and wait for the mouse to stop spinning (about a minute)

Click on the Browser button, if everything is working so far you will get a new browser window with “Hello world!” in the window.

Stop the test code by hitting the “stop” button

Now you need to replace main.php in the directory you selected for your code setup, you must go in to the new subdirectory (it has the same name as your application). You will find the main.php program you need to replace (the Hello World code) with the main.php you created and put your API Key and Secret in..

After you replace the main.php, go back into google app engine launcher, and reselect the application and Run it. After the mouse stops spinning (about a minute), click on the Browse button. You should get “No source given” as the output in the browser window that opens up. Awesome!

Stop the app

Click on Deploy

Enter your gmail account user name and password

Wait for it to successfully deploy (you are looking for a code 0)

Close the Google App Engine Launcher, your app is ready!

Step 9: How to Run Your New App, and Twitter T&C's, Display the Logo!

WOW... 10 steps to tweeting with RSS feeds.  You can use the app to get RSS feeds from any Twitter account, but others can't (shouldn't) use your app, as Twitter doesn't let (want) a 3rd Party using the app you created, that is registered to you...  To be in compliance you have to create your own app and register it and use the Twitter logo (in your display of the RSS feeds) to abide by the T&C's of Twitter (I am not a lawyer, so take no advice from me LOL).

To use your new app, simply enter the URL with these additions: ?name=TwitterID&count=3

example:  MyGoogleAppName.appspot.com/?name=npratc&count=10

After the ?name= you enter the Twitter ID of the person's tweets you want to see, in this case National Public Broadcasting's show All Things Considered "npratc".  After the &count= you enter the number of tweets (most recent ones first), you want to be in the feed, in this case 10.

Last make sure you use the Twitter Logo.... when displaying the feeds.  It is all part of the T&Cs you agreed to, here is a resource to get your twitter bird:

https://dev.twitter.com/docs/image-resources

Have Fun!
Make it a Tremendous Day tweeting via RSS feeds.


Step 10: Good Luck