Exemplo n.º 1
0
 public function authenticate()
 {
     /**
      * Array with the OAuth tokens provided by Twitter
      *   - consumer_key        Twitter API key
      *   - consumer_secret     Twitter API secret
      *   - oauth_token         Twitter Access token         * Optional For GET Calls
      *   - oauth_token_secret  Twitter Access token secret  * Optional For GET Calls
      */
     $credentials = array('consumer_key' => 'Lk9hAGCzZ6bKTP3dmI2UHGqyB', 'consumer_secret' => 'dRNmJP5WkHQZ8QmPT3WoM25sAG6SZdwJG5JnyRc5geLE5hY9sx', 'oauth_token' => '2186032518-WknupkqmLuF1dpZyMZSryqW64Ng4brQLR3ucds5', 'oauth_token_secret' => 'YM6a1z4FGCpOgvs4yh3SPUi1AYlEQQ1HW95jLLUlMcOeq');
     /**
      * Instantiate SingleUser
      *
      * For different output formats you can set one of available serializers
      * (Array, Json, Object, Text or a custom one)
      */
     $auth = new SingleUserAuth($credentials, new ArraySerializer());
     /**
      * Returns a collection of the most recent Tweets posted by the user
      * https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline
      */
     $params = array('screen_name' => 'Dharmen89390541', 'count' => 3, 'exclude_replies' => true);
     /**
      * Send a GET call with set parameters
      */
     $response = $auth->get('statuses/user_timeline', $params);
     echo '<pre>';
     print_r($auth->getHeaders());
     echo '</pre>';
     echo '<pre>';
     print_r($response);
     echo '</pre><hr />';
 }
Exemplo n.º 2
0
 public function getTwitter()
 {
     $credentials = array('consumer_key' => env("TWITTER_KEY"), 'consumer_secret' => env("TWITTER_SECRET"), 'oauth_token' => env("OAUTH_TOKEN"), 'oauth_token_secret' => env("OAUTH_SECRET"));
     $auth = new SingleUserAuth($credentials, new ArraySerializer());
     $params = array('screen_name' => 'LFF4EVER', 'count' => 50, 'exclude_replies' => true, 'include_rts' => false, 'trim_user' => true);
     $response = $auth->get('statuses/user_timeline', $params);
     // echo '<pre>'; print_r($auth->getHeaders()); echo '</pre>';
     // echo '<pre>'; print_r($response); echo '</pre><hr />';
     // echo '<pre>';
     // foreach($response as $r){
     // 	print $r['text']."<br>";
     // }
     // echo '</pre><hr />';
     $outputArray = [];
     $i = 0;
     foreach ($response as $r) {
         $outputArray[$i] = ['created_at' => $r['created_at'], 'text' => $r['text']];
         if (!empty($r['entities']['media'][0]['media_url'])) {
             $outputArray[$i] = array_merge($outputArray[$i], ['media' => $r['entities']['media'][0]['media_url']]);
         }
         $i++;
     }
     echo json_encode($outputArray);
 }
Exemplo n.º 3
0
use TwitterOAuth\Auth\SingleUserAuth;
use TwitterOAuth\Serializer\ArraySerializer;
$credentials = array('consumer_key' => 'fxy5RXmMPpvMyMlYWVMP0kqx3', 'consumer_secret' => 'LT29Fbr5OuVPs40OsyiOpFy7mpdqVUNo0zvEuFC59nk0VXRzJu', 'oauth_token' => $_SESSION['oauth_token'], 'oauth_token_secret' => $_SESSION['oauth_token_secret']);
$serializer = new ArraySerializer();
$auth = new SingleUserAuth($credentials, $serializer);
if ($_SESSION['oauth_token'] == $_GET['oauth_token']) {
    $params = array('oauth_verifier' => $_GET['oauth_verifier']);
    $response = $auth->post('oauth/access_token', $params);
    //         setcookie("oauth_token", $response['oauth_token'],0,'/');
    // 		setcookie("oauth_token_secret", $response['oauth_token_secret'],0,$path='/');
    $_SESSION['oauth_token'] = $response['oauth_token'];
    $_SESSION['oauth_token_secret'] = $response['oauth_token_secret'];
    $credentials = array('consumer_key' => 'fxy5RXmMPpvMyMlYWVMP0kqx3', 'consumer_secret' => 'LT29Fbr5OuVPs40OsyiOpFy7mpdqVUNo0zvEuFC59nk0VXRzJu', 'oauth_token' => $response['oauth_token'], 'oauth_token_secret' => $response['oauth_token_secret']);
    $auth = new SingleUserAuth($credentials, $serializer);
    $params = array('include_entities' => 'false', 'skip_status' => 'true', 'include_email' => 'true');
    $response = $auth->get('account/verify_credentials', $params);
    $twitter_user_id = $response['id'];
    $email = $response['email'];
    $screen_name = $response['screen_name'];
    $profile_image_url_https = $response['profile_image_url_https'];
    $sql = "select count(Id) AS alreadyRegisteredUser from users where twitter_user_id = :twitter_user_id";
    $query = $db->prepare($sql);
    $query->execute(array(':twitter_user_id' => $twitter_user_id));
    $row = $query->fetch();
    $newInserted = false;
    if ($row['alreadyRegisteredUser'] == 0) {
        $sql = "INSERT INTO users ( twitter_user_id, screen_name, email, profile_image ) VALUES ( :twitter_user_id, :screen_name, :email, :profile_image )";
        $query = $db->prepare($sql);
        $query->execute(array(':twitter_user_id' => $twitter_user_id, ':screen_name' => $screen_name, ':email' => $email, ':profile_image' => $profile_image_url_https));
        $newInserted = true;
    } else {
Exemplo n.º 4
0
date_default_timezone_set('UTC');
/**
 * Array with the OAuth tokens provided by Twitter
 *   - consumer_key        Twitter API key
 *   - consumer_secret     Twitter API secret
 *   - oauth_token         Twitter Access token         * Optional For GET Calls
 *   - oauth_token_secret  Twitter Access token secret  * Optional For GET Calls
 */
$credentials = array('consumer_key' => 'xvz1evFS4wEEPTGEFPHBog', 'consumer_secret' => 'L8qq9PZyRg6ieKGEKhZolGC0vJWLw8iEJ88DRdyOg', 'oauth_token' => 'e98c603b55646a6d22249d9b0096e9af29bafcc2', 'oauth_token_secret' => '07cfdf42835998375e71b46d96b4488a5c659c2f');
/**
 * Instantiate SingleUser
 *
 * For different output formats you can set one of available serializers
 * (Array, Json, Object, Text or a custom one)
 */
$auth = new SingleUserAuth($credentials, new ArraySerializer());
/**
 * Returns a collection of the most recent Tweets posted by the user
 * https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline
 */
$params = array('screen_name' => 'ricard0per', 'count' => 3, 'exclude_replies' => true);
/**
 * Send a GET call with set parameters
 */
$response = $auth->get('statuses/user_timeline', $params);
echo '<pre>';
print_r($auth->getHeaders());
echo '</pre>';
echo '<pre>';
print_r($response);
echo '</pre><hr />';
Exemplo n.º 5
0
                $(this).toggleClass('closed');
            });
    }
</script>
<style>
    pre{overflow:hidden;}
    .strip{margin-left:5px;width:90%;vertical-align:top;display:inline-block;word-wrap:break-word;}
    .closed{height:84px;cursor:pointer;}
</style>

<?php 
$credentials = array('consumer_key' => 'xvz1evFS4wEEPTGEFPHBog', 'consumer_secret' => 'L8qq9PZyRg6ieKGEKhZolGC0vJWLw8iEJ88DRdyOg', 'oauth_token' => 'e98c603b55646a6d22249d9b0096e9af29bafcc2', 'oauth_token_secret' => '07cfdf42835998375e71b46d96b4488a5c659c2f');
$auth = new SingleUserAuth($credentials, new ArraySerializer());
// ==== ==== ==== //
$params = array('screen_name' => 'ricard0per', 'count' => 3, 'exclude_replies' => true);
$response = $auth->get('statuses/user_timeline', $params);
echo '<strong>statuses/user_timeline</strong><br />';
echo '<pre class="array">';
print_r($auth->getHeaders());
echo '</pre>';
echo '<pre class="array">';
print_r($response);
echo '</pre><hr />';
// ==== ==== ==== //
$params = array('q' => '#php', 'count' => 3);
$response = $auth->get('search/tweets', $params);
echo '<strong>search/tweets</strong><br />';
echo '<pre class="array">';
print_r($auth->getHeaders());
echo '</pre>';
echo '<pre class="array">';