Skip to content

Instantly share code, notes, and snippets.

@howyi
Created July 16, 2015 03:25
Show Gist options
  • Save howyi/0681b96bc899a7d2dcbb to your computer and use it in GitHub Desktop.
Save howyi/0681b96bc899a7d2dcbb to your computer and use it in GitHub Desktop.
Tweet with twitterOAuth
<?php
session_start();
require "twitteroauth/autoload.php";
use Abraham\TwitterOAuth\TwitterOAuth;
$tw = "Tweet test";
define('CONSUMER_KEY', 'hoge');
define('CONSUMER_SECRET','foo');
define('OAUTH_CALLBACK', 'http://localhost');
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET,$_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
$access_token = $connection->oauth("oauth/access_token", array("oauth_verifier" => $_REQUEST['oauth_verifier']));
$_SESSION['oauth_token'] = $access_token["oauth_token"];
$_SESSION['oauth_token_secret'] = $access_token["oauth_token_secret"];
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET,$_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
$connection->post('statuses/update', array('status' => $tw));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment