query( sprintf('INSERT INTO twitter_user(username) VALUES("%s")', mysqli_real_escape_string( $mtdb->link, md5( microtime() )) ) ) ) {
adminlog("Error on insertion of new twitter user.", MTS_TWITTER, MTA_INSERT, E_WARNING);
mtdie("Error on insertion of new twitter user: ". htmlentities(mysqli_error()), 'SQL Error');
} else {
//$name = sanitize_username($_POST['name']);
$id = mysqli_insert_id();
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
$request_token = $connection->getRequestToken(OAUTH_CALLBACK . "&id=$id");
if ($connection->http_code !== 200 ) {
adminlog("Twitter getRequestToken failed. HTTP code: $connection->http_code", MTS_TWITTER, MTA_MODIFY);
mtdie("Could not connect to twitter.com.");
}
echo $id . '
';
setOAuthTokens( $id, $request_token['oauth_token'], $request_token['oauth_token_secret'], md5(microtime()) );
adminlog("New twitter user created successfully.", MTS_TWITTER, MTA_ADD);
$url = $connection->getAuthorizeURL($request_token['oauth_token']);
//echo $url;
_redirect($url);
exit();
}
}
if( isset($_REQUEST['action']) && $_REQUEST['action'] == 'twittercallback' && isset($_REQUEST['id'])) {
# twitter userID = ID
$id = (int)$_REQUEST['id'];
$row = $mtdb->getRow( sprintf('SELECT id, username, oauth_token, oauth_token_secret, oauth_access_token FROM twitter_user WHERE id=%d LIMIT 1', $id));
# Compare token in database with token from twitter. If they differ, bail.
if( $row->oauth_token != $_REQUEST['oauth_token'] ) {
# token is old, drop from database
if(!$mtdb->query("DELETE FROM twitter_user WHERE id = '$id'") ) {
adminlog('Error deleting temporary twitter user ' . $id, MTS_TWITTER, MTA_DELETE, E_ERROR);
mtdie('Error deleting temporary twitter user.', 'SQL Error');
}
$error.='
OAuth Token are Old
'; } else { # token is good, save the new Access Token to the database $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $row->oauth_token, $row->oauth_token_secret); $access_token = $connection->getAccessToken($_REQUEST['oauth_verifier']); if (200 == $connection->http_code) { # successful $info.='Successfully obtained OAuth Access Token.
'; $content = $connection->get('account/verify_credentials'); $username = $content->screen_name; setOAuthTokens($id, $access_token['oauth_token'], $access_token['oauth_token_secret'], $username); adminlog("Successfully received OAuth Access Tokens for twitter user.", MTS_TWITTER, MTA_MODIFY, E_WARNING); //print_r($content); } else { # fail if( !$mtdb->query("DELETE FROM twitter_user WHERE id = '$id'") ) { adminlog('Error deleting specified twitter user ' . $id, MTS_TWITTER, MTA_DELETE, E_ERROR); mtdie('Error deleting the specified twitter user.', 'SQL Error'); } $info.='Failed to get OAuth Access Token for ' . $username . '.
'; adminlog("Failed to get OAuth Access Tokens for twitter user.", MTS_TWITTER, MTA_MODIFY, E_ERROR); } } } $twitter_users = $mtdb->getAll('SELECT id, username, oauth_token, oauth_token_secret, oauth_access_token FROM twitter_user ORDER BY username'); adminhead('Manage Twitter Users'); adminmenu(); ?>Make changes to the twitter accounts which we can post to.
| ID # | Twitter.com Username | oauth_token | oauth_token_secret | Authorized | |
|---|---|---|---|---|---|
| id; ?> | username); ?> | oauth_token); ?> | oauth_token_secret); ?> | oauth_token, $s->oauth_token_secret);
$content = $connection->get('account/verify_credentials');
if( isset($content->profile_image_url)) {
echo ' |
Delete |