Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to --> Offer a coupon for a Tweet

Tags:

php

twitter

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:

  1. I need a link somewhere on my site that will have an offer: "Send a Twit and receive a coupon", right?

  2. 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"?

  3. 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...

like image 893
santa Avatar asked Jun 28 '11 14:06

santa


3 Answers

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):

  1. Build TwitterOAuth object using client credentials.
  2. Request temporary credentials from Twitter.
  3. Build authorize URL for Twitter.
  4. Redirect user to authorize URL.
  5. User authorizes access and returns from Twitter.
  6. Rebuild TwitterOAuth object with client credentials and temporary credentials.
  7. Query Twitter API.

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.)

like image 77
You Avatar answered Oct 16 '22 01:10

You


For the more lazy of us ;) This makes a button to pay with a tweet (like so enter image description here) 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).

like image 29
Tommy Bravo Avatar answered Oct 16 '22 01:10

Tommy Bravo


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.

like image 1
GregSchoen Avatar answered Oct 16 '22 03:10

GregSchoen