title: How to post a tweet using Codebird PHP from pop-up window
body: <p>I am trying to allow visitors to my site to post a tweet with an image directly from the site. I am using <a href="https://github.com/jublonet/codebird-php" rel="noreferrer">Codebird PHP library</a> to accomplish this. So far everything is working correctly, however there is no preview of the post before it gets posted to the user's account. Currently, it just posts directly to their account as soon as they click the button. </p>
  
  <p>What I would like is to have it pop-up a small window where it will ask them to log in if they aren't logged in yet, or it will show a preview of the tweet and allow them to click the "Tweet" button if they are logged in like in this image:</p>
  
  <p><a href="https://i.stack.imgur.com/bw97o.png" rel="noreferrer"><img src="https://i.stack.imgur.com/bw97o.png" alt="sample tweet popup window"></a></p>
  
  <p>Here's my PHP:</p>
  
  <pre><code>function tweet($message,$image) {
      require_once('codebird.php');
      \Codebird\Codebird::setConsumerKey("MYCONSUMERKEY", "MYCONSUMERSECRET");
      $cb = \Codebird\Codebird::getInstance();
      session_start();
  
      if (! isset($_SESSION['oauth_token'])) {
        // get the request token
        $reply = $cb-&gt;oauth_requestToken([
          'oauth_callback' =&gt; 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']
        ]);
  
        // store the token
        $cb-&gt;setToken($reply-&gt;oauth_token, $reply-&gt;oauth_token_secret);
        $_SESSION['oauth_token'] = $reply-&gt;oauth_token;
        $_SESSION['oauth_token_secret'] = $reply-&gt;oauth_token_secret;
        $_SESSION['oauth_verify'] = true;
  
        // redirect to auth website
        $auth_url = $cb-&gt;oauth_authorize();
        header('Location: ' . $auth_url);
        die();
  
      } elseif (isset($_GET['oauth_verifier']) &amp;&amp; isset($_SESSION['oauth_verify'])) {
        // verify the token
        $cb-&gt;setToken($_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
        unset($_SESSION['oauth_verify']);
  
        // get the access token
        $reply = $cb-&gt;oauth_accessToken([
          'oauth_verifier' =&gt; $_GET['oauth_verifier']
        ]);
  
        // store the token (which is different from the request token!)
        $_SESSION['oauth_token'] = $reply-&gt;oauth_token;
        $_SESSION['oauth_token_secret'] = $reply-&gt;oauth_token_secret;
  
        // send to same URL, without oauth GET parameters
        header('Location: ' . basename(__FILE__));
        die();
      }
  
      // assign access token on each page load
      $cb-&gt;setToken($_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
      $reply = $cb-&gt;media_upload(array(
          'media' =&gt; $image
      ));
      $mediaID = $reply-&gt;media_id_string;
      $params = array(
          'status' =&gt; $message,
          'media_ids' =&gt; $mediaID
      );
      $reply = $cb-&gt;statuses_update($params);
  }
  
  tweet("Tweet tweet","assets/tweet.jpg");
  </code></pre>
  
  <p>And here's my Javascript/HTML:</p>
  
  <pre><code>function postTweet() {
    $.ajax({
      type: "POST",
      url: 'tweet.php',
      data:{action:'call_this'},
      success:function(html) {
        alert('Success!');
      }
    });
  }
  &lt;button class="download-share" onclick="postTweet()"&gt;Download and Share&lt;/button&gt;
  </code></pre>