<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Twitter Archives - gj</title>
	<atom:link href="https://blog.gaiterjones.com/tag/twitter/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.gaiterjones.com/tag/twitter/</link>
	<description>gaiterjones</description>
	<lastBuildDate>Fri, 09 Dec 2011 16:41:45 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.4.3</generator>
	<item>
		<title>Magento Automated Social Media Marketing FREE Extension &#8211; Twitter, Facebook</title>
		<link>https://blog.gaiterjones.com/magento-automated-social-media-marketing/</link>
					<comments>https://blog.gaiterjones.com/magento-automated-social-media-marketing/#comments</comments>
		
		<dc:creator><![CDATA[PAJ]]></dc:creator>
		<pubDate>Thu, 15 Sep 2011 11:33:16 +0000</pubDate>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Free Magento Extensions]]></category>
		<category><![CDATA[Marketing]]></category>
		<category><![CDATA[marketing tweets]]></category>
		<category><![CDATA[Social Media Marketing]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[free magento extension]]></category>
		<category><![CDATA[Magento]]></category>
		<guid isPermaLink="false">http://blog.gaiterjones.com/?p=548</guid>

					<description><![CDATA[This Magento module provides an automated social media marketing solution by generating Magento product marketing social media posts to Twitter and Facebook when a customer places an order. How it...<a class="more-link" href="https://blog.gaiterjones.com/magento-automated-social-media-marketing/" title="Continue reading">Continue reading</a>]]></description>
										<content:encoded><![CDATA[<p><img decoding="async" class="hang-2-column     alignnone" title="Magento Automated Social Media Marketing FREE Extension" src="https://blog.gaiterjones.com/wp-content/uploads/2011/03/buyxgeyfree-box.jpg" alt="Magento Automated Social Media Marketing FREE Extension" width="168" height="168" /><br />
This Magento module provides an automated social media marketing solution by generating Magento product marketing social media posts to Twitter and Facebook when a customer places an order.</p>
<h1><strong>How it Works</strong></h1>
<p>The code in the module is called at checkout and a random product is selected from products in  the customers cart. The information from this random &#8220;Top Seller&#8221; product is used to create a product marketing post, including a headline, short description and short Bit.ly URL to link to the product page. The built in Magento scheduling system is then used to regularly check for new marketing posts and send them to Twitter and Facebook.</p>
<figure id="attachment_17" aria-describedby="caption-attachment-17" style="width: 528px" class="wp-caption alignnone"><img fetchpriority="high" decoding="async" class="size-full wp-image-17" title="Example automated product marketing tweet" src="https://blog.gaiterjones.com/wp-content/uploads/2010/12/Image12.jpg" alt="Example automated product marketing tweet" width="528" height="102" srcset="https://blog.gaiterjones.com/wp-content/uploads/2010/12/Image12.jpg 528w, https://blog.gaiterjones.com/wp-content/uploads/2010/12/Image12-300x57.jpg 300w" sizes="(max-width: 528px) 100vw, 528px" /><figcaption id="caption-attachment-17" class="wp-caption-text">Example automated product marketing tweet</figcaption></figure>
<p>&nbsp;</p>
<p>To use this module you must enable the Magento scheduling system and will need a Twitter  account, and configured Twitter application, a Facebook account and configured Facebook application and a Bit.ly account, further information for setting these accounts up is detailed below.</p>
<figure id="attachment_565" aria-describedby="caption-attachment-565" style="width: 425px" class="wp-caption alignnone"><img decoding="async" class="size-full wp-image-565" title="Magento Automated Social Media Marketing Facebook Example" src="https://blog.gaiterjones.com/wp-content/uploads/2011/09/social-media-marketing-twitter-6.jpg" alt="Magento Automated Social Media Marketing Facebook Example" width="425" height="136" /><figcaption id="caption-attachment-565" class="wp-caption-text">Example automated Facebook post</figcaption></figure>
<p>&nbsp;</p>
<p>Tested with Magento CE 1.6.1</p>
<p>I am looking for <strong>extension testers</strong>, <a href="https://blog.gaiterjones.com/dev/extension.php?id=2f7ab7ec9e088352b822073749d6e7d0" target="_blank">download BETA version 0.26 (last updated 09-12-2011) of the extension <strong>here</strong></a></p>
<p><strong>Updates</strong></p>
<p>If you use this extension be sure to update to the latest version.</p>
<p>*  0.22 &#8211; First beta release. 15.09.2011<br />
*  0.23 &#8211; Developed Facebook integration and duplicate post control logic. 16.09.2011<br />
* 0.24 &#8211; Improved Facebook posting, added logic to exclude posts for products in specified categories. 19.09.2011<br />
* 0.25 &#8211; Added time range to stop being too <em>spammy</em> by restricting posts to specific hours of the day. 04.11.2011<br />
* 0.26 &#8211; Fixed grouped products not being posted due to hidden child simple products of the parent group product.</p>
<p><strong>Wishlist</strong></p>
<p>Implement logic to control the duplication of product Tweets. Done &#8211; v0.23<br />
Extend to other Social Media platforms, Facebook, etc. Facebook Support in v0.23<br />
Implement hash tags for Twitter.<br />
Add to Cart link in Facebook posts<br />
Add option to use Short or Long description text.</p>
<h1><strong>Installation</strong></h1>
<p>Prerequisites :</p>
<p>Enable Magento scheduling system<br />
Twitter Account<br />
Twitter Application<br />
Facebook Account<br />
Authorised Facebook Application</p>
<p>Bit.ly Account (optional)</p>
<p>To install this extension:</p>
<p><strong>1.</strong> Unzip the module and copy the contents of the modules app folder to the app folder of your Magento store installation.</p>
<p><strong>2</strong>. Ensure that the module /cache and /cache/Bitly folders have write permissions set to allow the WWW user group write access. The module stores the product Tweets and caches the Bit.ly short URLs in this folder.</p>
<p><strong>3</strong>. Refresh the Magento Store cache</p>
<p><strong>4.</strong> Logout and login back into the admin backend, goto System &#8211; Configuration and locate the configuration settings under My Extensions &#8211; Social Media Marketing.</p>
<h1><strong>Configuration</strong></h1>
<p>1. Configure the Twitter, Facebook and Bit.ly account, authorisation and API keys. See below for further information. If you do not want to use the Bit.ly short URL service set the enable option to no.</p>
<p>Twitter is enabled by default, Facebook is disabled by default.</p>
<p>2. Define a headline prefix for the product marketing text, the default if left blank is &#8220;Top Seller:&#8221; To disable this prefix enter NONE. For Facebook you can define the text to use for the post header. Define the &#8220;uniqueness&#8221; value for posts, this value will be used to check for if a product has already been posted in the last X posts, where X is the value you define here. This will help prevent duplicate posts. You can also configure a time range so that Social Media Marketing posts will only be made during the times selected.</p>
<p>3. Configure Google UTM tags for traffic tracking in Google analytics.e.g. ?utm_source=SocialMediaMarketing&amp;utm_medium=Top-Seller&amp;utm_campaign=MyCampaig</p>
<figure id="attachment_608" aria-describedby="caption-attachment-608" style="width: 620px" class="wp-caption alignnone"><a href="https://blog.gaiterjones.com/wp-content/uploads/2011/09/SocialMediaMarketingUTMTagsMagento.jpg"><img loading="lazy" decoding="async" class="size-large wp-image-608" title="Google Analytics Magento Social Media Marketing Revenue Report" src="https://blog.gaiterjones.com/wp-content/uploads/2011/09/SocialMediaMarketingUTMTagsMagento-620x95.jpg" alt="" width="620" height="95" srcset="https://blog.gaiterjones.com/wp-content/uploads/2011/09/SocialMediaMarketingUTMTagsMagento-620x95.jpg 620w, https://blog.gaiterjones.com/wp-content/uploads/2011/09/SocialMediaMarketingUTMTagsMagento-440x67.jpg 440w, https://blog.gaiterjones.com/wp-content/uploads/2011/09/SocialMediaMarketingUTMTagsMagento.jpg 1423w" sizes="(max-width: 620px) 100vw, 620px" /></a><figcaption id="caption-attachment-608" class="wp-caption-text">Example Google Analytics Magento Social Media Marketing Revenue Report</figcaption></figure>
<p>&nbsp;</p>
<p>4. Enable email alerts which will help you debug the module during testing.</p>
<p>5. Save the extension configuration settings and test.</p>
<h1><strong>Testing</strong></h1>
<p>Make a test order in your store to test the extension. Upon checkout completion the product marketing information will be written to the modules cache folder. At the next scheduled Magento task execution the text will be posted to Twitter (and Facebook if enabled) and the cached file deleted.</p>
<p>To force the Magento scheduler to run navigate to <strong>http://www.yourwebshop.com/cron.php</strong>. Check your Twitter and Facebook pages to confirm the marketing post has been submitted. Any errors that occur during this process will be emailed to the default store email address if you set email alerts enabled to <em>YES</em> in the configuration.</p>
<figure id="attachment_556" aria-describedby="caption-attachment-556" style="width: 440px" class="wp-caption alignnone"><img loading="lazy" decoding="async" class="size-medium wp-image-556" title="Magento Social Media Marketing - example product tweet" src="https://blog.gaiterjones.com/wp-content/uploads/2011/09/social-media-marketing-twitter-4-440x70.jpg" alt="Magento Social Media Marketing - example product tweet" width="440" height="70" srcset="https://blog.gaiterjones.com/wp-content/uploads/2011/09/social-media-marketing-twitter-4-440x70.jpg 440w, https://blog.gaiterjones.com/wp-content/uploads/2011/09/social-media-marketing-twitter-4.jpg 533w" sizes="(max-width: 440px) 100vw, 440px" /><figcaption id="caption-attachment-556" class="wp-caption-text">example product tweet</figcaption></figure>
<h1></h1>
<h1><strong><strong><strong><strong>ENABLE MAGENTO SCHEDULING</strong></strong></strong></strong></h1>
<p>Magento uses a single file named <strong>cron.php</strong> to execute all its scheduled tasks –  cron.php should be executed regularly to allow configured background tasks in Magento to run and is also used by this module to check for marketing information to post. For example to run cron.php every 5 minutes add the following or similar to your crontab (crontab -e):</p>
<p><em>*/5 * * * * /usr/bin/php -f  /PATH-TO-MAGENTO/cron.php</em></p>
<p>Alternatively for testing you can execute cron.php from your browser by browsing to</p>
<p><em>http://www.yourstore.com/cron.php</em></p>
<p>&nbsp;</p>
<h1><strong><strong>TWITTER Configuration<br />
</strong></strong></h1>
<p>Folow the steps below to create a Twitter application that will be used by the module to access your Twitter account and post product marketing Tweets.</p>
<p>1. If you do not already have a Twitter account, create an account at <a href="http://www.tiwtter.com">http://www.tiwtter.com</a></p>
<p>2. Go to <a href="https://dev.twitter.com/">https://dev.twitter.com/</a> and login with your Twitter credentials.</p>
<p>3. Click the Create an App link.</p>
<p>4. Complete the first page of the application form with your application name, description and website address. A Callback URL is not required. Click the &#8220;Create your twitter app&#8221; button to continue.</p>
<figure id="attachment_552" aria-describedby="caption-attachment-552" style="width: 440px" class="wp-caption alignnone"><img loading="lazy" decoding="async" class="size-medium wp-image-552" title="Magento Social Media Marketing - configure a twitter application" src="https://blog.gaiterjones.com/wp-content/uploads/2011/09/social-media-marketing-twitter-1-440x271.jpg" alt="Magento Social Media Marketing - configure a twitter application" width="440" height="271" srcset="https://blog.gaiterjones.com/wp-content/uploads/2011/09/social-media-marketing-twitter-1-440x271.jpg 440w, https://blog.gaiterjones.com/wp-content/uploads/2011/09/social-media-marketing-twitter-1-620x382.jpg 620w, https://blog.gaiterjones.com/wp-content/uploads/2011/09/social-media-marketing-twitter-1.jpg 981w" sizes="(max-width: 440px) 100vw, 440px" /><figcaption id="caption-attachment-552" class="wp-caption-text">configure a twitter application</figcaption></figure>
<p>&nbsp;</p>
<p>5. Goto the application settings tab and ensure your application is set to <strong>Read and Write</strong> and click Update Setting to continue.</p>
<figure id="attachment_553" aria-describedby="caption-attachment-553" style="width: 440px" class="wp-caption alignnone"><img loading="lazy" decoding="async" class="size-medium wp-image-553" title="Magento Social Media Marketing - configure a twitter application" src="https://blog.gaiterjones.com/wp-content/uploads/2011/09/social-media-marketing-twitter-2-440x151.jpg" alt="Magento Social Media Marketing - configure a twitter application" width="440" height="151" srcset="https://blog.gaiterjones.com/wp-content/uploads/2011/09/social-media-marketing-twitter-2-440x151.jpg 440w, https://blog.gaiterjones.com/wp-content/uploads/2011/09/social-media-marketing-twitter-2-620x213.jpg 620w, https://blog.gaiterjones.com/wp-content/uploads/2011/09/social-media-marketing-twitter-2.jpg 637w" sizes="(max-width: 440px) 100vw, 440px" /><figcaption id="caption-attachment-553" class="wp-caption-text">ensure the application has read write access</figcaption></figure>
<p>&nbsp;</p>
<p>6. Click on the details tab and scroll down to the Create my access Token button, click it to create access tokens for the application. You will see the four main authentication tokens listed CONSUMER KEY, CONSUMER SECRET, ACCESS TOKEN and ACCESS TOKEN SECRET. Ensure that the access tokens have READ and WRITE access.</p>
<p>7. Copy each authentication token into the configuration settings of the module and click save.</p>
<p>If you do not want to use Bit.ly to shorten URLs in the marketing tweets you have the option of enabling t.co shortlinks in the application settings and you can disable Bit.ly in the extension settings.</p>
<p>You can confirm your application is enabled and has access to your Twitter account by going to account settings -&gt; applications in Twitter.</p>
<figure id="attachment_554" aria-describedby="caption-attachment-554" style="width: 440px" class="wp-caption alignnone"><img loading="lazy" decoding="async" class="size-medium wp-image-554" title="Magento Social Media Marketing - configure a twitter application" src="https://blog.gaiterjones.com/wp-content/uploads/2011/09/social-media-marketing-twitter-3-440x95.jpg" alt="Magento Social Media Marketing - configure a twitter application" width="440" height="95" srcset="https://blog.gaiterjones.com/wp-content/uploads/2011/09/social-media-marketing-twitter-3-440x95.jpg 440w, https://blog.gaiterjones.com/wp-content/uploads/2011/09/social-media-marketing-twitter-3-620x134.jpg 620w, https://blog.gaiterjones.com/wp-content/uploads/2011/09/social-media-marketing-twitter-3.jpg 633w" sizes="(max-width: 440px) 100vw, 440px" /><figcaption id="caption-attachment-554" class="wp-caption-text">confirm application is enabled</figcaption></figure>
<h1></h1>
<h1>FACEBOOK CONFIGURATION</h1>
<p>Login to Facebook and then browse to</p>
<p><a href="http://developers.facebook.com/">http://developers.facebook.com/</a></p>
<p>Create an application that will be used to post marketing information to your Facebook page, this can be a normal profile page or a Business/Fan page. When complete note the application ID and application secret.</p>
<p>The application must be authorised for your Facebook page to work.</p>
<p>To authorise the application for your page edit the following URL and paste to your browser, replaceing YOURAPIKEY and YOURPAGEID..</p>
<p>facebook.com/connect/prompt_permissions.php?api_key=YOURAPIKEY&amp;v=1.0&amp;next=http://www.facebook.com/connect/login_success.html?xxRESULTTOKENxx&amp;display=popup&amp;ext_perm=publish_stream&amp;enable_profile_selector=1&amp;profile_selector_ids=YOURPAGEID</p>
<h1></h1>
<h1>BIT.LY CONFIGURATION</h1>
<p>To create a Bit.ly account goto <a href="http://bit.ly">http://bit.ly</a> and register an account. Once registered obtain your API key by clicking on Account -&gt; Settings. Configure your bit.ly username and API key in the configuration settings of the extension and save them.Bit.ly is enabled by default in the extension, If you do not want to use bit.ly you can disable it in the configuration settings.</p>
<p>&nbsp;</p>
<p><strong><strong><br />
</strong></strong></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.gaiterjones.com/magento-automated-social-media-marketing/feed/</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
			</item>
		<item>
		<title>Automatic Magento Product Marketing Tweets for Twitter</title>
		<link>https://blog.gaiterjones.com/automatic-magento-product-marketing-tweets-for-twitter/</link>
					<comments>https://blog.gaiterjones.com/automatic-magento-product-marketing-tweets-for-twitter/#comments</comments>
		
		<dc:creator><![CDATA[PAJ]]></dc:creator>
		<pubDate>Tue, 28 Dec 2010 16:04:31 +0000</pubDate>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[Social Media Marketing]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[Marketing Tweets]]></category>
		<guid isPermaLink="false">http://blog.gaiterjones.com/?p=5</guid>

					<description><![CDATA[THIS MAGENTO HACK IS NOW A MAGENTO MODULE/EXTENSION, CLICK HERE FOR MORE INFO Wouldn&#8217;t it be great if your customers could do your twitter product marketing for you? Thats what...<a class="more-link" href="https://blog.gaiterjones.com/automatic-magento-product-marketing-tweets-for-twitter/" title="Continue reading">Continue reading</a>]]></description>
										<content:encoded><![CDATA[<p><a title="Magento Automated Social Media Marketing FREE Extension – Twitter, Facebook" href="https://blog.gaiterjones.com/magento-automated-social-media-marketing/"><strong>THIS MAGENTO HACK IS NOW A MAGENTO MODULE/EXTENSION, CLICK HERE FOR MORE INFO</strong></a></p>
<p>Wouldn&#8217;t it be great if your customers could do your twitter product marketing for you? Thats what I thought after seeing a few automated marketing posts coming up in my twitter feed. So I set about looking at my own automated marketing tweets triggered when a customer placed an order in our Magento e-commerce store. The goal was to randomly select a product from the last order &#8211; a so called &#8220;Top Seller&#8221;, wrap it up nicely in a 140 char tweet with a URL to the product page and post it to twitter automatically from the onepage checkout success page as the customer completed checkout. After a day or so of development I came up with a solution that looks something like this on Magento 1.3.3.0 using the test database.</p>
<figure id="attachment_17" aria-describedby="caption-attachment-17" style="width: 528px" class="wp-caption alignnone"><a href="https://blog.gaiterjones.com/wp-content/uploads/2010/12/Image12.jpg"><img loading="lazy" decoding="async" class="hang-1-column  " style="border: 1px solid black;" title="Example automated product marketing tweet" src="https://blog.gaiterjones.com/wp-content/uploads/2010/12/Image12.jpg" alt="Example automated product marketing tweet" width="528" height="102" /></a><figcaption id="caption-attachment-17" class="wp-caption-text">Example automated product marketing tweet</figcaption></figure>
<h2>Step 1 &#8211; Installing in Magento</h2>
<p>To integrate the code into Magento you can either use the onepage checkout success.phtml file to call the code after checkout, or if you have already developed your own Magento code modules you can create a new template phtml file and test the code by calling  it from a CMS block in Magento  i.e.</p>
<pre class="brush:xml">&lt;div&gt;{{block type="MY_Page/view" template="Page/tweet.phtml"}}&lt;/div&gt;</pre>
<p>If you use success.phtml you will need to submit an order from your webshop to test the code, if you are using CMS simply browse to the CMS page you created, i.e. <em>http://www.mysite.com/tweet</em></p>
<p>Here is the working code to use either in your own phtml template file or to append to success.phtml in your frontend themes template files.</p>
<pre class="brush:php">&lt;?php
// Magento Product Twitter Marketing
//
// paj
// www.gaiterjones.com
// tested with Magento 1.3.3.0
// v1.0

// Short URL function
function make_bitly_url($url,$login,$appkey,$format = 'xml',$history = 1)
{
//create the URL
	$bitly = 'http://api.bit.ly/v3/shorten?login='.$login.'&amp;apiKey='.$appkey.'&amp;uri='.urlencode($url). '&amp;format='.$format.'&amp;history='.$history;

//get the url
$response = file_get_contents($bitly);

//parse depending on desired format

	if(strtolower($format) == 'json')
		{
			$json = @json_decode($response,true);
			return $json['data']['url'];
		}
	elseif(strtolower($format) == 'xml') //xml
		{

			$xml = simplexml_load_string($response);
			return $xml-&gt;data-&gt;url;
		}
	elseif(strtolower($format) == 'txt') //text
		{
			return $response;
		}
}

// Get last order from Magento session.
$orderId = Mage::getModel('sales/order')-&gt;load(Mage::getSingleton('checkout/session')-&gt;getLastOrderId());
$order = Mage::getModel('sales/order')-&gt;load($orderId);
$items = $order-&gt;getAllItems();
$itemcount=count($items);
//$name=array();
//$unitPrice=array();
//$sku=array();
$ids=array();
//$qty=array();

try
{

// Build arrays, uncomment as needed to populate arrays with more order information, SKU, price etc.
foreach ($items as $itemId =&gt; $item)
{
	// $name[] = $item-&gt;getName();
	// $unitPrice[]=$item-&gt;getPrice();
	// $sku[]=$item-&gt;getSku();
	// we are only interested in the product id
	$ids[]=$item-&gt;getProductId();
	// $qty[]=$item-&gt;getQtyToInvoice();

//	echo $name[$itemId]. ' - ' .$sku[$itemId]. ' - €'. $unitPrice[$itemId]. '&lt;br&gt;';
}

	do {

	shuffle ($ids);
	$rand_keys = (count($ids) &gt; 1)?array_rand($ids, $itemcount):array_keys($ids);
	$custom = Mage::getModel('catalog/product')-&gt;load($ids[$rand_keys[0]]);

	// Make sure the product is visible in catalog
	if ($custom-&gt;getVisibility()==4) {

	// twitter text prefix, this will appear before your product description
	$twitter_txt=$this-&gt;__('Top Seller'). ": ";

	// twitter txt URL - add a short URL to the product using bit.ly API
	$shorturl=make_bitly_url($custom-&gt;getProductUrl(),'YOUR-BITLY-USERNAME','YOUR-BITLY-API');

	// The text between our tweet and the shorturl when the tweet is longer than 140 chars
	$twitter_txt_suffix = '... ';
	$chars_remaining=140-(strlen($shorturl)+strlen($twitter_txt_suffix));

	// debugging echos comment these out when testing complete.
	// Check lengths of short url, prefix etc.
	echo $shorturl. ' is '. strlen($shorturl). ' chars.&lt;br&gt;';
	echo 'Suffix and URL are '. (strlen($shorturl)+strlen($twitter_txt_suffix)). ' chars.&lt;br&gt;';
	echo 'Characters remaining for tweet : '. $chars_remaining. '&lt;br&gt;';

	// Prepare tweet text
	$twitter_txt=$twitter_txt . strip_tags(str_replace("&lt;br /&gt;",", ",substr($custom-&gt;getDescription(), 0, strpos($custom-&gt;getDescription(), '.')+1))). ' ';

	// Make sure we only tweet 140 chars or less

		if (strlen($twitter_txt) &lt;= $chars_remaining) {
			$twitter_txt = $twitter_txt; //do nothing
		}
		else {
			$twitter_txt = wordwrap($twitter_txt, $chars_remaining);
			$twitter_txt = substr($twitter_txt, 0, strpos($twitter_txt, "\n"));
			$twitter_txt = $twitter_txt. $twitter_txt_suffix;
		}

	// Complete tweet text with short url.
	$twitter_txt = $twitter_txt. ' ' .$shorturl;

	// Get ready to tweet
	$accessToken = file_get_contents("/home/www/classes/twitteroauth/access_token");
	$accessTokenSecret = file_get_contents("/home/www/classes/twitteroauth/access_token_secret");

	// Create our twitter API object
	require_once('/home/www/classes/twitteroauth/twitteroauth.php');
	$oauth = new TwitterOAuth('YOUR-TWITTER-CONSUMER-KEY', 'YOUR-TWITTER-CONSUMER-SECRET', $accessToken, $accessTokenSecret);

	// Send an API request to verify credentials
	$credentials = $oauth-&gt;get("account/verify_credentials");
	echo "Connected as @" . $credentials-&gt;screen_name. '&lt;br&gt;';

	// TWEEET, uncomment to tweet.
	//$oauth-&gt;post('statuses/update', array('status' =&gt; $twitter_txt));

	// debugging echos comment these out when testing complete.
	echo 'Simulated tweet : ('. strlen($twitter_txt). ' chars long.)&lt;br&gt;&lt;br&gt;';
	echo '&lt;strong&gt;'. $twitter_txt. '&lt;/strong&gt;&lt;br&gt;';

	}

	} while ($custom-&gt;getVisibility()!=4);

// debugging use this to catch any errors, remove error message when testing complete.
} catch (Exception $ex) { echo "An Error was detected."; }		

?&gt;</pre>
<p>Copy and paste the code at the end of your one page checkout success.phtml file or paste it into a new template phtml file i.e. tweet.phtml.</p>
<p>The first function is used to create a shortened URL via the bit.ly API, for this you will need a bit.ly account and your bit.ly API key (available form the settings menu in your account). We are only really interested in the product ids from the order, but if you want to use other information in your tweet remove the comments from the array loop.</p>
<p>$twitter_txt contains our tweet text. It starts out with a prefix &#8220;Top Sellers&#8221; and then uses an excerpt from the Magento product description to create the rest of the tweet text.</p>
<pre class="brush:php">$twitter_txt=$twitter_txt . strip_tags(str_replace("&lt;br /&gt;",", ",substr($custom-&gt;getDescription(),0, strpos($custom-&gt;getDescription(), '.')+1))). ' ';</pre>
<p>My product descriptions text always includes the product name on the first line of the long description text followed by a line break e.g.</p>
<pre class="brush:groovy">&lt;p&gt;&lt;strong&gt;Nokia 2610 Phone&lt;/strong&gt;&lt;br /&gt;The Nokia 2610 is an easy to use device that combines multiple messaging options including email, instant messaging, and more.</pre>
<p>We strip out the HTML replacing the first html line break with a comma and then search for the next full stop to extract the first sentence from our description. (This is also a good technique I have used  for<a href="https://blog.gaiterjones.com/magento-seo-generate-meta-description-tags-automatically/"> automatic SEO meta description tags for products</a>.)  If your product descriptions do not include line breaks you will need to play with this code so that it extracts a product description that suits your requirements.</p>
<p>We need to make sure our tweet including prefix and short url are less than 140 chars so we use some code to check how long the tweet product description text is and shorten it if required adding a &#8220;&#8230;&#8221; suffix. Now we have our tweet text and call the Twitter oAuth code to authenticate and post the tweet. The code that makes the tweet is commented, and for testing the tweet text will be echoed out so you can easily debug your tweet and description text, the simulated tweet should look something like this:</p>
<pre>http://bit.ly/hd6Et1 is 20 chars.
Suffix and URL are 24 chars.
Characters remaining for tweet : 116
Connected as @your-twitter-username
Simulated tweet : (135 chars long.)
<strong>Top Seller: Nokia 2610 Phone, The Nokia 2610 is an easy to use device </strong><strong>that combines multiple messaging options... http://bit.ly/hC6Et1</strong></pre>
<figure id="attachment_25" aria-describedby="caption-attachment-25" style="width: 519px" class="wp-caption alignnone"><a href="https://blog.gaiterjones.com/wp-content/uploads/2010/12/Image5.jpg"><img loading="lazy" decoding="async" class="hang-1-column     " style="border: 1px solid black;" title="Debugging the tweet text from a CMS page" src="https://blog.gaiterjones.com/wp-content/uploads/2010/12/Image5.jpg" alt="Debugging the tweet text from a CMS page" width="519" height="266" /></a><figcaption id="caption-attachment-25" class="wp-caption-text">Debugging the tweet text from a CMS page</figcaption></figure>
<p>See below for setting up your twitter application and installing the oAuth code.</p>
<p>Note that you need to have an order in the current magento session, I haven&#8217;t yet figured out how to access the last order outwith the user session, so if you don&#8217;t see anything or see the exception error echoed out make sure you are logged into your magento shop and have placed a test order.</p>
<h2>Step 2 &#8211; Twitter PHP oAuth Code</h2>
<p>The Twitter oAuth authentication process is complex and way beyond my programming skills, however <a href="http://abrah.am/">Abraham Williams</a> has developed the PHP code to perform the twitter oAuth authentication and posting for us. Download the code <a href="https://github.com/abraham/twitteroauth/zipball/0.2.0-beta3">here</a>. Open the ZIP folder and extract the twitteroauth folder to a suitable area on your development host. For example /home/www/classes. The folder contains two PHP files, twitteroauth.php and OAuth.php that are called from our code, update the script include so that the path to your oAuth files is correct.</p>
<h2><strong>Step 3 &#8211; Twitter Application and Access Codes</strong></h2>
<p>Obviously to create a twitter app you need a twitter account. Login to your twitter account and go to <a href="http://dev.twitter.com/apps/new" target="_blank">http://dev.twitter.com/apps/new</a> to register a new twitter app.  Complete the registration by choosing an application name, note this name will appear under your posts! Set the application type to client and make sure you set the application type to read &amp; write.</p>
<p>When you have registered your application take a note of the <strong>Consumer Key</strong> and <strong>Consumer Secret</strong>. Click on the My Access Token right hand menu link and take a note of your <strong>Access Token (oauth_token)</strong> and <strong>Access Token Secret (oauth_token_secret)</strong>.</p>
<p>Copy and paste your Twitter Consumer Key and Consumer Secret into the script.</p>
<pre class="brush:php">$oauth = new TwitterOAuth('YOUR-TWITTER-CONSUMER-KEY','YOUR-TWITTER-CONSUMER-SECRET', $accessToken, $accessTokenSecret);</pre>
<p>The Twitter Access Token and Access Token Secret can be included in plain text in the script but for security I am separating them out into two seperate files located with my oauth PHP scripts:</p>
<pre class="brush:php">$accessToken = file_get_contents("/home/www/classes/twitteroauth/access_token");
$accessTokenSecret = file_get_contents("/home/www/classes/twitteroauth/access_token_secret");</pre>
<p>So either modify the strings above to contain your access codes as plain txt i.e. $accessToken=&#8221;MY-ACCESS-TOKEN&#8221;;  or create your own folder and paths to two files containing your twitter access keys in plain text.</p>
<h2>Step 4 &#8211; Test</h2>
<p>If you have copied the code to your success.phtml file make an order and you should see the simulated tweet with your product description on your one page checkout success page.</p>
<pre>http://bit.ly/hd6Et1 is 20 chars.
Suffix and URL are 24 chars.
Characters remaining for tweet : 116
Connected as @your-twitter-username
Simulated tweet : (135 chars long.)
<strong>Top Seller: Nokia 2610 Phone, The Nokia 2610 is an easy to use device </strong><strong>that combines multiple messaging options... http://bit.ly/hC6Et1</strong></pre>
<p>To make a test tweet uncomment the tweet statement and place another order, check your twitter account for a new tweet!</p>
<p>When you are happy with your tweet text, uncomment the debugging echos from the script and test again.</p>
<figure id="attachment_17" aria-describedby="caption-attachment-17" style="width: 528px" class="wp-caption alignnone"><a href="https://blog.gaiterjones.com/wp-content/uploads/2010/12/Image12.jpg"><img loading="lazy" decoding="async" class="hang-1-column   " style="border: 1px solid black;" title="Example automated product marketing tweet" src="https://blog.gaiterjones.com/wp-content/uploads/2010/12/Image12.jpg" alt="Example automated product marketing tweet" width="528" height="102" /></a><figcaption id="caption-attachment-17" class="wp-caption-text">Example automated product marketing tweet</figcaption></figure>
<h2><strong>Conclusions and further ideas</strong></h2>
<p>Twitter marketing can easily become Twitter spam, depending on how many orders a day your shop is getting you may need to throttle back the number of product tweets you make, the tweet could also be handled elsewhere in the app, or from a cron job that picks a random product each day. I like the idea of the &#8220;Top Seller&#8221; from an actual order, and that the customer was actually doing the marketing work for you! You may also want to extract your parent categories to create additional hash tags for your tweets to improve search results, although this will eat up your precious 140 chars.</p>
<p>Some Googled resources used in creating this solution:</p>
<p><a href="http://articles.sitepoint.com/article/oauth-for-php-twitter-apps-part-1">http://articles.sitepoint.com/article/oauth-for-php-twitter-apps-part-1</a><br />
<a href="http://subesh.com.np/2010/03/ordered-items-detail-order-id-magento/">http://subesh.com.np/2010/03/ordered-items-detail-order-id-magento/</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.gaiterjones.com/automatic-magento-product-marketing-tweets-for-twitter/feed/</wfw:commentRss>
			<slash:comments>7</slash:comments>
		
		
			</item>
	</channel>
</rss>
