Пример #1
0
function post_tweets($post_texts, $userdata)
{
    foreach ($post_texts as $i => $text) {
        echo 'POST:' . PHP_EOL;
        echo $text . PHP_EOL;
        if (DEBUG) {
            continue;
        }
        $to = new TwistOAuth($userdata->twitter_consumer_key, $userdata->twitter_consumer_key_secret, $userdata->twitter_access_token, $userdata->twitter_access_token_secret);
        $url = 'statuses/update';
        $param = array('status' => $text);
        try {
            $res = $to->post($url, $param);
        } catch (TwistException $e) {
            var_dump($e);
        }
    }
}
Пример #2
0
function template_tweet()
{
    global $array, $CK, $CS, $AT, $AS, $hashtag;
    printstr($array);
    print "gochiusa/temp > ";
    $stdin = trim(fgets(STDIN));
    try {
        $to = new TwistOAuth($CK, $CS, $AT, $AS);
        while (!($stdin === "exit")) {
            echo "you tweet ";
            echo $array[$stdin] . " #" . $hashtag . "\n";
            $to->post('statuses/update', array('status' => $array[$stdin] . " #" . $hashtag));
            printstr($array);
            print "gochiusa/temp > ";
            $stdin = trim(fgets(STDIN));
        }
    } catch (TwistException $e) {
        //set error message
        $error = $e->getMessage();
        $code = $e->getCode() ?: 500;
    }
}
Пример #3
0
 /**
  * Set cURL options for oauth_verifier.
  *
  * @param resource   $ch
  * @param TwistOAuth $to
  * @param string     $authenticity_token
  * @param string     $username
  * @param string     $password
  */
 private static function curlSetOptForVerifier($ch, $to, $authenticity_token, $username, $password)
 {
     $params = array('session[username_or_email]' => $username, 'session[password]' => $password, 'authenticity_token' => $authenticity_token);
     curl_setopt_array($ch, array(CURLOPT_URL => $to->getAuthorizeUrl(true), CURLOPT_POSTFIELDS => http_build_query($params, '', '&'), CURLOPT_POST => true));
 }
Пример #4
0
 * Created by PhpStorm.
 * User: kmasaya
 * Date: 30/11/2015
 * Time: 19:07
 */
if (empty($argv[1])) {
    exit('Usage:php cron.php screen_name' . PHP_EOL);
}
$screen_name = $argv[1];
if (!empty($argv[2])) {
    $rcount = $argv[2];
} else {
    $rcount = 3;
}
require '../config.php';
require 'TwistOAuth.phar';
$to = new TwistOAuth(CK, CS, AT, ATS);
$count = '5000';
//取得数
//$rcount = '20';      //リムーブ数
/* Follow取得 */
$follow = $to->get('friends/ids', array('screen_name' => $screen_name, 'count' => $count));
/* FollowerID取得 */
$follower = $to->get('followers/ids', array('screen_name' => $screen_name, 'count' => $count));
$f_difference = array_diff($follow->ids, $follower->ids);
$remove = array_slice($f_difference, 0, $rcount);
foreach ($remove as $rem) {
    $to->post('friendships/destroy', array('user_id' => $rem));
    print $rem . ' ';
    sleep(3);
}
Пример #5
0
 * User: kmasaya
 * Date: 2015/12/02
 * Time: 13:05
 */
if (empty($argv[1])) {
    exit('Usage:php cron.php screen_name' . PHP_EOL);
}
$screen_name = $argv[1];
if (!empty($argv[2])) {
    $fcount = $argv[2];
} else {
    $fcount = 3;
}
require '../config.php';
require 'TwistOAuth.phar';
$to = new TwistOAuth(CK, CS, AT, ATS);
$count = '5000';
//取得数
$myscreen_name = 'HaloDsny';
//自分のTwitter名
/* MyFollowing取得 */
$mefollowing = $to->get('friends/ids', array('screen_name' => $myscreen_name, 'count' => $count));
/* Target FollowerID取得 */
$target = $to->get('followers/ids', array('screen_name' => $screen_name, 'count' => $count));
$f_difference = array_diff($target->ids, $mefollowing->ids);
//自フォローとターゲットフォロワー差分
$following = array_slice($f_difference, 100, $fcount);
foreach ($following as $fol) {
    $to->post('friendships/create', array('user_id' => $fol));
    print $fol . ' ';
    sleep(5);
Пример #6
0
}));
try {
    // Download TwistOAuth.phar into the temporary directory
    $path = sys_get_temp_dir() . '/TwistOAuth.phar';
    if (!is_readable($path)) {
        switch (true) {
            case !($local = @fopen($path, 'wb')):
            case !($remote = @fopen('https://raw.githubusercontent.com/mpyw/TwistOAuth/master/build/TwistOAuth.phar', 'rb')):
            case !@stream_copy_to_stream($remote, $local):
                $error = error_get_last();
                throw new \RuntimeException($error['message']);
        }
    }
    require $path;
    // Create TwistOAuth
    $to = new \TwistOAuth($consumer_key, $consumer_secret, $oauth_token, $oauth_token_secret);
    // Create DateTimeZone
    $tz = new \DateTimeZone($timezone);
    // Get home timeline
    $statuses = $to->get('statuses/home_timeline', array('count' => 200));
} catch (\Exception $e) {
    header('Content-Type: text/plain; charset=UTF-8', true, 500);
    echo $e->getMessage() . "\n";
    exit;
}
header('Content-Type: text/html; charset=UTF-8');
?>
<!DOCTYPE html>
<html>
<head>
    <title>Test</title>
Пример #7
0
<?php

require_once 'lib/TwistOAuth.php';
require_once 'lib/TwistException.php';
define('CONSUMER_KEY', '取得したキー');
define('CONSUMER_SECRET', '取得したキー');
define('ACCESS_TOKEN', '取得したキー');
define('ACCESS_TOKEN_SECRET', '取得したキー');
try {
    $to = new TwistOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
} catch (TwistException $e) {
    $error = $e->getMessage();
    echo $error . PHP_EOL;
}
// parameter
$params = array("count" => 5);
// end point
$url = "https://api.twitter.com/1.1/statuses/home_timeline.json";
// response
$res = $to->get($url, $params);
foreach ($res as $tweet) {
    echo $tweet->text . "\n";
}
Пример #8
0
<?php

require_once 'lib/TwistOAuth.php';
require_once 'lib/TwistException.php';
define('CONSUMER_KEY', '取得したキー');
define('CONSUMER_SECRET', '取得したキー');
define('ACCESS_TOKEN', '取得したキー');
define('ACCESS_TOKEN_SECRET', '取得したキー');
try {
    $to = new TwistOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
} catch (TwistException $e) {
    $error = $e->getMessage();
    echo $error . PHP_EOL;
}
// tweet text
$text = "そろそろ行くか";
// parameter
$params = array("status" => $text);
// end point
$url = "https://api.twitter.com/1.1/statuses/update.json";
$to->post($url, $params);
Пример #9
0
 function tweet($text)
 {
     $to = new TwistOAuth(TWITTER_COSUMER_KEY, TWITTER_COSUMER_SECRET, TWITTER_ACCESS_TOKEN, TWITTER_TOKEN_SECRET);
     $to->post('statuses/update', array('status' => $text));
 }
Пример #10
0
<?php

require_once __DIR__ . "/bootstrap.php";
use HirotoK\SaveTweet\App\SaveTweet;
use HirotoK\SaveTweet\App\Cache;
if (config("https") && !is_https()) {
    header("location: https://" . config("url") . "/show.php");
    exit;
}
header("Content-Type: text/html; charset=utf-8", true);
try {
    $conf = config("twitter");
    $TwistOAuth = new TwistOAuth($conf["ck"], $conf["cs"], $conf["ot"], $conf["os"]);
    $SaveTweet = new SaveTweet(config("db"), $TwistOAuth);
    $Cache = new Cache($TwistOAuth);
    $filter = [];
    $user = filter_input(INPUT_GET, "user");
    if (!empty($user) && is_string($user)) {
        foreach (explode(",", $user) as $sn) {
            $filter[] = $sn;
        }
    }
    $user_ids = [];
    $names = [];
    $create_cache = [];
    foreach ($SaveTweet->tweetsList() as $row) {
        $user_ids[] = $row["user_id"];
    }
    if (count($user_ids) !== 0) {
        $statuses = $TwistOAuth->get("users/lookup", ["user_id" => implode(",", array_values(array_unique($user_ids)))]);
        foreach ($statuses as $status) {
Пример #11
0
/*

crontab -e
0 1 * * * cd /your_dir/backend/; php cron.php 39ff
*/
/*if (array_shift(get_included_files()) === __FILE__) die('Only cli'); */
if (empty($argv[1])) {
    exit('Usage:php cron.php screen_name' . PHP_EOL);
}
$screen_name = $argv[1];
require 'TwistOAuth.phar';
require '../config.php';
try {
    $pdo = new PDO(sprintf('mysql:dbname=%s;host=%s;charset=%s', DBNAME, DBHOST, DBCHARSET), DBUSER, DBPASS, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_EMULATE_PREPARES => false));
    $to = new TwistOAuth(CK, CS, AT, ATS);
    $data = $to->get('users/show', array('screen_name' => $screen_name));
    //friends_count
    //followers_count
    $pdo->beginTransaction();
    $sql = 'INSERT INTO analytics(screen_name,twitter_id,follower,following,fetched_date) VALUES(?,?,?,?,?)';
    $stmt = $pdo->prepare($sql);
    $stmt->execute(array($screen_name, $data->id, $data->followers_count, $data->friends_count, date('Y-m-d H:i:s')));
    $stmt->closeCursor();
    $pdo->commit();
} catch (Exception $e) {
    //var_dump($e->getMessage());
    $export['code'] = 500;
    //rollback when failed.
    $pdo->rollBack();
}