I've seen recently a few times when companies offer either a download link or a coupon code for people that will tweet about it. It is all automated and I would like to do something like this but I'm not quite clear on the process.
Usually you go to a page with a link. You click on a link and it asks if you would give permission for some Tweeter app to connect to your profile. You grant permission and it brings up a pre-composed twitter message, something like: "I just got a coupon to try out..." Once the twitter message is sent, you are re-directed to a page where you find your coupon code.
I use PHP and can write whatever is needed to get this done.
Anyone knows how it is all done?
Update:
OK, I downloaded http://code.google.com/p/oauth-php/still not clear what to do next.
I am trying to figure out startuing with this page: http://code.google.com/p/oauth-php/wiki/ConsumerHowTo#Two-legged_OAuth
The way I understand the process the following should take place in this order:
I need a link somewhere on my site that will have an offer: "Send a Twit and receive a coupon", right?
Once they click on the offer link, how do I populate a message into their twitter update window: "Trying out this tool for free: http"//mylink.com"?
Once they submit Twitter post, I suppose I will have some settings that will redirect back to my site to a page with a coupon.
UPDATE: switched to twitteroauth, but still need help...
Basically, you have to create an app that uses the OAuth API to connect to twitter and post a tweet. This takes several steps (assuming you've registered your application with Twitter, giving you a key and secret):
Using TwitterOAuth, it would look something like this:
<?php
require_once 'TwitterOAuth.php';
define('THIS', 'http://example.org/tweet.php'); // Absolute URI to script
if(isset($_GET['callback']) {
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET,
$_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
$connection->post('statuses/update', array('status' => 'Coupon message'));
header('Location: coupon.php'); // Supplies user with coupon
} else {
$connection = new TwitterOAuth('key', 'secret'); // Key & secret from Twitter
$temporary_credentials = $connection->getRequestToken(THIS.'?');
$redirect_url = $connection->getAuthorizeURL($temporary_credentials, FALSE);
header('Location: '.$redirect_url.'&callback');
}
?>
(Note that the above code is untested; read the documentation of TwitterOAuth before doing things yourself.)
For the more lazy of us ;) This makes a button to pay with a tweet (like so ) and links to an URL of your choice afterwards. I guess you could reach most off your goals with this (though coupon codes that are personal might be tricky).
You could use Abraham's Twitter OAuth Library, I would suggest it as it makes the OAuth flow incredibly easy.
What you'll want to do is make a link like "Tweet about this to get a free download" or whatever. That link will redirect them to authorize your Twitter Application, when the callback comes back to your site, you request an Access Token and save it. This page should have a text box pre-populated with your message that posts to your site with the message that they want to send. You'll do an API call to post the message with the access token you received. Once you make the call and post the tweet, show them the page for the download.
Take a look at the TwitterOAuth Library Documentation as it has detailed examples on how to use the library to make the calls you're looking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With