Well, yeah but-
“So why 3.0 so soon?”
Good question.
When I finally sat down to make autoTweet 2.0 I unwittingly did so without the knowledge that twitter was doing away with their current method of making API calls (read more about this here: http://dev.twitter.com/announcements). The new method requires OAuth to make API calls and is basically going to render autoTweet useless. This does however make using twitter apps far more secure. Also, since it’s a new method I decided to go ahead and make it a 3.0 (i was never good with these naming conventions). Just be happy it’s not 2.0.1.b R2 beta 4.
New Features
- Uses OAuth to verify twitter user.
- Added real time error reporting
- Added ability to set twitter time out.
Requirements
- php5+
- JSON support
- cURL
- Zen Cart 1.3.8 or greater
Set up
Anyway to get started with the new twitter method we’re going to have to create a web app via twitter that we can access using a single access token.
1. first you need to log into your store’s twitter account and create an application on twitter http://dev.twitter.com/apps/new
2. Fill in the information boxes like so:
a. Application Name: Just use your store’s name or URL. I simply used store’s address: Htmyell.com
b. Description: You need to enter at least a 10 character description. Once again I used Htmyell.com
c. Application Website: your store’s URL, i.e. https://www.htmyell.com
d. Application Type: Make sure you set this to “Browser” if it’s not already set for you.
e. Callback URL: This isn’t important to us, since we wont need to be making any requests. Just enter your store’s URL again:
f. Make sure you set this to “Read & Write” if it is not already set for you.
g. Application Icon: Your logo, pic, etc.
Anything else you can fill in however you want, or leave blank. Note: you can come back and change this at any time.
Now prove you’re real, click register application, then accept the terms.
3. Now you’ll be redirected to you application details page. There you should be given two important things; your Consumer Key, and your Consumer Secret.
4. Extract everything the autoTweet3.zip. Open the included update_product.php from the in admin/includes/modules/ folder and edit the information you see between quotes on lines 92 and 93 with your information
5. Now back at your Application Details page you should see a link on the right hand side called “My Access Token”, click on it. This page gives you your single access token of the twitter account that you created the application with. Use this information to fill in lines 94 and 95 back in update_product.php.
6. Now edit lines 96 through 100 like so:
a. $twitUsername = your twitter user name.
b. $twitPassword = your twitter password.
c. $bitlyUsername = your bit.ly user name (available for free at www.bit.ly)
d. $bitApiKey = your bit.ly API Key, find it by logging in to bit.ly and clicking settings.
e. $storeUrl = The web address to your store’s home page. (Might be something like www.mystore.com or www.myname.com/store) Note: the “”http://”” before the url is not needed here.
f. $showprice = If you want to show your product’s price on twitter set this equal to 1 (with no quotes.) If you don’t want to set your product’s price set this equal to 0 (default).
g. $timeout = the amount of time (in seconds) to wait for twitter before moving on and just adding the product. This makes it so that your store doesn’t break waiting for twitter. No quotes here either.
7. Save and Upload
Save the file. Now upload the contents of your autoTweet 3.0 admin folder to your store’s admin folder. This will replace your existing update_product.php file with the new autoTweet version and add the twitteroauth folder. So if prompted, allow overwriting.
Download:
Download now from Zen-Cart.com
Thanks Jamie. I’ve just added this to my site and it works great. Your clear instructions made it really easy.
It’s currently set up to tweet the item price before tax. Is there a way I can modify the code to show the price with VAT and to restrict the output to two decimal places?
Yeah, you could multiply it by .whatever the VAT is:
So if VAT was 8% you would change line 122 to something like:
$vat = .08;
if ($showprice){ $message .= ‘ Only $’ . number_format(( $products_price + $products_price * $vat), 2, ‘.’, ”) . ‘!’; }
also you can see that by wrapping the equation in the number_format() function above we’ve ensured that we show and restrict the price to decimals.