How to --> Offer a coupon for a Tweet How to --> Offer a coupon for a Tweet php php

How to --> Offer a coupon for a Tweet


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


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


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.