I'll show you how to use Twitter with Amazon to create a revenue stream.
This lens will take you through the steps to set up your own Twitter account which will tweet updates from Amazon that link to your Amazon Associates ID.
A little bit of programming knowledge is required, but nothing too complex. It took me longer to write up this page than it did to start my coding from scratch - having never used the languages and tools before!
The idea is that people follow your tweets, click on your links to Amazon products, and then make a purchase. You get a %age of that purchase.
Imagine the returns you could make if you get a million followers on Twitter and they all decide to buy the latest products...
OK, lets not get carried away just yet. Instead take the time out to review what I've written here and then go away and create your own means to corner your market and start watching the cash roll in.
Before we really get started, check out the Twitter 101 Special Guide for Business, lots of useful info there.
STOP PRESS! STOP PRESS! STOP PRESS! Wealth & Health Warning
Be aware of Amazon T&Cs
This means that links from Twitter or from URL shortening sites such as bit.ly or tinyurl won't earn you any revenue.
More info and comment can be found on Blogstorm
Oh well. I'll leave this lens here for future reference.
What You Will Need
Get your coffee and take a seat.
Also my code isn't professionally written - in the sense that there is no error checking and handling etc. and the structure and efficiency can definitely be improved. The purpose of this page is to give you an overview of the bare essentials.
Before we proceed I'd be grateful if you would follow a couple of my Twitter accounts that use the techniques that you'll learn on this page. As these accounts might only tweet every few hours if you sign up now then by the time you have worked through this page you should start to see the tweets appearing and you'll get to see what the end result looks like.
If you haven't got a Twitter account go and sign up now at www.twitter.com. Then follow these two links....
- GiftsMostWanted which follows the ever changing lists of products given as gifts, and those most wished for at Amazon US
- MostWantedGifts which follows the same lists at Amazon UK
OK, so let's get started with the checklist of tools and accounts you'll need.
- A computer - I guess you already have one of these as you are reading this. I've recently moved from the Windows world to Mac and it is a revelation. So easy to work with. I'd recommend it.
- PHP - If you have a Mac the chances are this is already installed. If you don't have it on your Mac or Windows box you can download the latest version from www.php.com
- cURL - If you have a Mac... (see, it gets boring quickly, the Mac already has all this stuff). If you don't have cURL you can download it from curl.haxx.se
- A Twitter account - Visit www.twitter.com and set up an account for this project. If you already have a twitter account just use that one to start with.
- An Amazon AWS Subscription ID - Ah, we are getting technical now. If you want to query the Amazon Web Services, which we do, you'll need to sign up to get a Subscription ID. It's free so just visit aws.amazon.com and sign up.
- An Amazon Affiliates Tag - so that you can claim your commission from sales you need to sign up to the Amazon Associates programme. I'll use the Amazon.com Associates programme for this example, but you can use your local Amazon and modify my scripts accordingly. Visit the Amazon home page, scroll to the foot of the page and follow the "Join Associates" link.
What Are We Trying To Do
How do we get the cash in our pocket?
We know that people like to buy bestsellers. These items are bestsellers because others have already bought them and so they come highly recommended.
So we need a way to find out what the bestsellers are and advertise these to people.
Amazon very kindly update their list of bestsellers and top deals every hour - this provides an amazing insight into what people are buying right now.
Twitter provides a fantastic means for us to send updates to everyone who cares to follow our tweets so that we can inform them of the bestselling top deal that they really should take a further look at.
So all we need to do is to periodically take a look at the top selling item on Amazon and then tweet information about the item, and a link to the item with our Associates tag embedded of course.
Then we sit back and wait for the bank transfer.
OK, let's go.
Getting The Amazon Bestseller List
How do we find the bestsellers?
But that would be rather tedious.
Instead we'll use some simple code to get our computer to do that for us.
The simple code is based on the Amazon Product Advertising API which "provides programmatic access to Amazon's product selection and discovery functionality so that developers like you can advertise Amazon products to monetize your website".
First of all we need to know which bestseller or top deals list we want to focus on. Notice that i keep mentioning bestsellers and top deals - I don't know why it is but from a programming viewpoint we can get bestseller lists from Amazon UK, whereas we get top deals lists from Amazon US. Hence my two different Twitter account names of BestsellerUSA and BestsellerUK. It's not a big deal, just something to bear in mind that the Amazon Web Services aren't quite the same the world over.
Amazon likes to structure its products into categories that are based around a Browse Node. We need to find the Browse Node for the category that we want to focus on.
Amazon provides a list of Browse Nodes IDs for each region. The Amazon.com (US) list of Browse Nodes is what we are interested in here.
I'm going to select Soundtracks (under the Music SearchIndex) for the rest of this example. You'll see that Soundtracks has a Browse Node of 42.
And here is the URL for our query to get the list of Gadget top deals. You'll have to put in your SubscriptionID as indicated, then paste the URL into your browser and see what comes back.
Note that if you aren't using Amazon (US) then you need to change the 'ecs.amazonaws.com' server address to suit your local Amazon target e.g. ecs.amazon.aws.co.uk for the UK, use .fr for France etc.
http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&SubscriptionId=[your subscription ID]&Operation=BrowseNodeLookup&BrowseNodeId=42&ResponseGroup=TopSellers
I get the following unformatted string of information:
1T3AQCNB4DBRNDRNV0EE0.0199368000030518True42TopSellers42SoundtracksB001ED7C58Twilight SoundtrackB0018CK5RWHit Man: David Foster And Friends (CD+DVD)B001PK479OHannah Montana: The MovieB0000TB01YWicked (2003 Original Broadway Cast)B001JL43NOTwilight: The ScoreB001Z920NAStar TrekB001S2Q2XSAstral Weeks Live At The Hollywood Bowl: The Concert Film (Amazon.com Exclusive)B0024OW1L6True BloodB001LX0JK6Slumdog MillionaireB0028SVXVMChess in Concert
A quick scan will show that the 'Twilight Soundtrack' is top of the list and it has an ASIN (Amazon's product ID) of B001ED7C58. I've highlighted that in bold in the text above.
Looking at the page source we can see the XML that provides some structure around the response. Here is a snippet.
<BrowseNode>
<BrowseNodeId>42</BrowseNodeId>
<Name>Soundtracks</Name>
<TopSellers>
<TopSeller>
<ASIN>B001ED7C58</ASIN>
<Title>Twilight Soundtrack</Title>
</TopSeller>
etc.
So we have our list of bestsellers. Now we need a way to construct our query to send to Amazon, and then a means to process the XML that is returned. Once we can get the ASIN we can make another query to get further information such as the price.
Writing The Code
Let's give cURL a whirl.
The Wikipedia page on cURL gives a great starting point on using cURL to grab URL responses and write them to files. I tried this using the Amazon Web Service calls shown above and got back exactly what I wanted.
I then tried to post to Twitter using cURL. It was a doddle. You can try this yourself right now (this is all one line):
curl -u "[Your Twitter ID]:[Your Twitter Password]" -d "status=Cool, I'm updating Twitter from cURL" http://www.twitter.com/statuses/update.xml
I won't go into the details of all the options you can use for cURL but the basics that I've used there are '-u' to provide a username and password and '-d' which provides the data.
To read more about how I came to know that these were the right calls and the right Twitter url just Google for some inspiration - there is stacks of info out there on how to do this.
Great! So now we know we can get our info from Amazon and can post a tweet to Twitter.
I'm thinking that what we need to post to Twitter is something that tells our followers what the product is and how much it costs. Then a link to the product on Amazon to take them straight there.
So we need to be able to parse the XML that Amazon returns in order to get the ASIN, make another call to Amazon to get the details about the product. Parse the XML that is returned from that call and build a tweet, and then finally post the tweet to Twitter.
I had a quick look at cURL and found that doing everything from there wasn't the answer. cURL is great at doing what it does - i.e. messing around with URLs, but I need some glue to hold everything together.
It looked liked I needed to find out more about this PHP stuff...
My First PHP Script
Let's not bother with 'Hello World!' - that's way too predictable.
Time to roll up my sleeves and find out more about this language that so far in my life I've managed to live without.
So I'll start with something easy. Let's take the cURL Twitter update that I showed above and we'll wrap that in PHP. I'm shamelessly ripping code snippets that I've found on-line to do this. Feel free to do the same.
<?php
$tweet = "Cool, I'm updating Twitter from cURL from PHP";
$pwd = "[Your Twitter ID]:[Your Twitter Password]";
$ch = curl_init("http://twitter.com/statuses/update.xml");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, $pwd);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "status=" . $tweet);
$return = curl_exec($ch);
curl_close($ch);
?>
It's pretty obvious to see how the cURL command line options map to the PHP code. Ignore the other stuff, it just works so let's leave it at that for now.
Save your php script as squidoo.php, or whatever, then go to the command line and type:
$ php squidoo.php
And if all is well nothing should happen, i.e. you are just returned back to a waiting command prompt.
If there are issues with libraries, paths etc. etc. then sorry, I can't help. You'll need to work out how to get PHP, cURL etc. installed and configured on your machine. On my Mac I was pleased to see that all this just works, no messing with configurations and installations.
Now point your browser to Twitter. You should see your latest tweet. Congratulations! We are getting there.
Get The Details
cURL, Amazon, PHP, XML, it's all coming together.
Let's fire up our PHP editor - i.e. the most basic line editor you can find - and crack on. Creating something like the code below.
<?php
$url = "http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&SubscriptionId=[Your Subscription ID Here]&Operation=BrowseNodeLookup&BrowseNodeId=42&ResponseGroup=TopSellers";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$aws_data = curl_exec($ch);
curl_close($ch);
$xml = simplexml_load_string($aws_data);
//print_r($xml);
$asin = $xml->BrowseNodes->BrowseNode->TopSellers->TopSeller[0]->ASIN;
print $asin . "\n";
?>
Nothing too difficult there. Most of it should look familiar. The new stuff is after the cURL calls. I use the simplexml_load_string function in PHP to take the aws (Amazon Web Services) data and put it into variable that I can easily parse.
The next line features probably the most useful function in PHP: print_r
Use print_r to dump the xml data in a nice easy to read format. I've commented it out in the snippet above, but if you remove the two forward slashes you can see how it works.
The print_r output will point you where you need to go to find the ASIN of the top seller. That is what the next line does. Using TopSeller[0] points us to the ASIN of the item at the top of the list - i.e. the best selling item.
Finally we print the ASIN to check that all is correct. You can copy this ASIN from your command line and put it into the Amazon search box in your browser. If everything is working well you will be taken to the appropriate product page.
To get the item details we simply make another call to Amazon and include the ASIN - highlighted in bold in the snippet below.
<?php
:
All the stuff above
:
$url = "http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&Operation=ItemLookup&SubscriptionId=[Your Subscription ID]&AssociateTag=[Your Associate Tag]&ItemId=" . $asin . "&ResponseGroup=ItemAttributes";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$detailresponse = curl_exec($ch);
curl_close($ch);
$xml = simplexml_load_string($detailresponse);
//print_r($xml);
$tweet = "New! Amazon Soundtrack #1 Top Deal - " . $xml->Items->Item->ItemAttributes->Title . " @ " . $xml->Items->Item->ItemAttributes->ListPrice->FormattedPrice;
print $tweet;
?>
As before, there is nothing too complex and difficult there. We just take the ASIN, make another structured call to Amazon. Parse the XML (and use print_r to find the structure) then pull together various bits from the XML to create the tweet and we print it out just to be sure that things are working fine.
Tweet to Twitter
Let's tell the world!
There is just one small step to do. We need to add the Amazon product URL, with our Associates Tag to our tweet. However the Amazon URL is quite lengthy and might be two long for our limited tweet size, it will also look quite messy.
So we need to make the url tiny.
Let's bring TinyURL to the party.
It's easy to convert the Amazon URL to a TinyURL. Here is the code snippet:
<?php
:
All the stuff above
:
$url = "http://tinyurl.com/api-create.php?url=" . $xml->Items->Item->DetailPageURL;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$tinyurl = curl_exec($ch);
curl_close($ch);
$tweet = $tweet . " " . $tinyurl;
print $tweet;
?>
All we have to do now is tweet. And we did that using PHP earlier so I'll leave it as an exercise for you to complete the script.
And we are done.
Automate The Tweets
Update Twitter even while you are sleeping
Now we know that Amazon update their lists hourly, so we should look to run our script every hour - but no more often, you don't want to spam all your followers.
That's easy in Windows - using the Scheduler, and on your Mac you'll want to run a cron job. I'll leave that as another exercise for you to investigate...
Now you have the bare bones of the script you can look to modify it and to learn more about PHP. Some ideas for modification:
1. Only tweet when the bestselling item changes. So sometimes when your script runs it won't tweet as there is nothing new to tell people. This is probably more valuable to your followers as they only get updates for new stuff.
2. Use other best seller lists and monitor those. You could create a script for each list, or include all the lists in a single script and cycle through them.
3. Look for other affiliate programs that you could make use of.
4. Post ideas etc. in the feedback form below.
I trust you've enjoyed this short intro and that you've learned something from it. The potential is enormous and it is so easy to do.
And share your success stories in the feedback form below!
Bedtime Reading
If you want to find out more about PHP, check out these books.
Feedback Please
Sorry, but I can't give support on configuration, PHP, XML, AWS etc.
-
Reply
- Liam_Tohms Liam_Tohms Oct 9, 2009 @ 11:10 am
- I've changed the account names as they reflect the lists I'm following. This lens has been updated to reflect the new account names. Thanks for the reminder.
-
Reply
- snoglicker snoglicker Oct 6, 2009 @ 3:48 pm
- So sad that your account is no longer active on Twitter, I was trying to follow up but not noticed that your account doesn't exist anymore.
Good luck
-
Reply
- Ladydove62 Ladydove62 Jul 10, 2009 @ 7:58 pm
- Really great lens. Not sure if I can manage this quite yet but it is certainly food for fodder.One ? Have you monetized on this technique?
-
Reply
- tonytheblue tonytheblue Jul 2, 2009 @ 11:26 am
- Very interesting! I will be giving it a go.
Thanks, Tony
-
Reply
- motherbunny motherbunny Jun 26, 2009 @ 2:46 pm
- Love the lens, realy good info thank you soooo much Jackie



