Пример #1
0
<?php

require dirname(__DIR__) . '/vendor/autoload.php';
// Autoload files using Composer autoload
use j3j5\TwitterApio;
$api = new TwitterApio();
$followers_ids = array();
$i = 1;
$max_pages = 5;
$username = '******';
foreach ($api->get_followers(array('screen_name' => $username, 'count' => 5)) as $followers) {
    echo "Retrieving page {$i} ";
    if (!empty($followers) && is_array($followers)) {
        echo "with " . count($followers) . " followers." . PHP_EOL;
        $followers_ids = array_merge($followers_ids, $followers);
    } else {
        echo "(empty)." . PHP_EOL;
    }
    if ($i == $max_pages) {
        break;
    }
    $i++;
}
echo PHP_EOL . PHP_EOL;
echo count($followers_ids) . " retrieved in total from the API." . PHP_EOL;
return;
Пример #2
0
<?php

require dirname(__DIR__) . '/vendor/autoload.php';
// Autoload files using Composer autoload
use j3j5\TwitterApio;
$api = new TwitterApio();
$all_tweets = array();
$i = 1;
$max_pages = 5;
$username = '******';
foreach ($api->get_timeline('search/tweets', array('q' => $username, 'count' => 20)) as $tweets) {
    echo "Retrieving page {$i} ";
    if (!empty($tweets) && is_array($tweets)) {
        echo "with " . count($tweets) . " tweets." . PHP_EOL;
        $all_tweets = array_merge($all_tweets, $tweets);
    } else {
        echo "(empty)." . PHP_EOL;
    }
    if ($i == $max_pages) {
        break;
    }
    $i++;
}
echo PHP_EOL . PHP_EOL;
echo count($all_tweets) . " retrieved in total from the API." . PHP_EOL;
foreach ($all_tweets as $tweet) {
    echo "{$tweet['created_at']}: {$tweet['text']}" . PHP_EOL;
}
return;
Пример #3
0
<?php

require_once dirname(__DIR__) . '/vendor/autoload.php';
// Autoload files using Composer autoload
use j3j5\TwitterApio;
$api = new TwitterApio();
$result = $api->get('account/verify_credentials');
if (isset($result['id'])) {
    echo "Your user @{$result['screen_name']} has ID '{$result['id']}' and name '{$result['name']}'." . PHP_EOL;
} else {
    $config_path = dirname(__DIR__) . "/src/j3j5/config.php";
    echo "An error occured, did you fill the config.php file?" . PHP_EOL;
    echo "It should be on {$config_path}" . PHP_EOL;
}
return;
Пример #4
0
<?php

require dirname(__DIR__) . '/vendor/autoload.php';
// Autoload files using Composer autoload
use j3j5\TwitterApio;
session_start();
$api = new TwitterApio();
$current_url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$current_url = mb_substr($current_url, 0, mb_strpos($current_url, '?') - 1);
if (isset($_REQUEST['function'])) {
    if ($_REQUEST['function'] == 'login') {
        // your SIGN IN WITH TWITTER button should point to this route
        $sign_in_twitter = TRUE;
        $force_login = FALSE;
        $callback_url = $current_url . '?function=callback';
        // Make sure we make this request w/o tokens, overwrite the default values in case of login.
        $api->reconfigure(array('token' => '', 'secret' => ''));
        $token = $api->get_request_token($callback_url);
        if (isset($token['oauth_token_secret'])) {
            $url = $api->get_authorize_url($token, $sign_in_twitter, $force_login);
            $_SESSION['oauth_state'] = 'start';
            $_SESSION['oauth_request_token'] = $token['oauth_token'];
            $_SESSION['oauth_request_token_secret'] = $token['oauth_token_secret'];
            header("Location: {$url}");
            exit;
        }
        header("Location: {$current_url}?function=error");
        exit;
    } else {
        if ($_REQUEST['function'] == 'callback') {
            // You should set this route on your Twitter Application settings as the callback
Пример #5
0
<?php

require dirname(__DIR__) . '/vendor/autoload.php';
// Autoload files using Composer autoload
use j3j5\TwitterApio;
$api = new TwitterApio();
$all_tweets = array();
$i = 1;
$max_pages = 5;
$username = '******';
foreach ($api->get_timeline('statuses/user_timeline', array('screen_name' => $username, 'count' => 20)) as $tweets) {
    echo "Retrieving page {$i} ";
    if (!empty($tweets) && is_array($tweets)) {
        echo "with " . count($tweets) . " tweets." . PHP_EOL;
        $all_tweets = array_merge($all_tweets, $tweets);
    } else {
        echo "(empty)." . PHP_EOL;
    }
    if ($i == $max_pages) {
        break;
    }
    $i++;
}
echo PHP_EOL . PHP_EOL;
echo count($all_tweets) . " retrieved in total from the API." . PHP_EOL;
foreach ($all_tweets as $tweet) {
    echo "{$tweet['created_at']}: {$tweet['text']}" . PHP_EOL;
}
return;