librecat/include/tw-post.php

34 lines
860 B
PHP

<?php
use Abraham\TwitterOAuth\TwitterOAuth;
function post_tweet($text){
if(!isset($_SESSION["uid"])){
echo("Couln't post tweet. User not logged in.");
die();
}
$db = new SQLite3('../ask.db');
$user = $db->query("SELECT * FROM users where id = " . $_SESSION["uid"] . ";")->fetchArray(SQLITE3_ASSOC);
if($user["tw_oauth_token"] == "" || $user["tw_oauth_verify"] == ""){
echo("Your account isn't linked to a twitter account");
die();
}
require('../include/twitteroauth/autoload.php');
include("../twitter.secret");
define('CONSUMER_KEY', $consumer_key);
define('CONSUMER_SECRET', $consumer_secret);
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $user["tw_oauth_token"], $user["tw_oauth_verify"]);
$connection->setTimeouts(10, 15);
$statues = $connection->post("statuses/update", ["status" => $text]);
}
?>