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 />';
 }
Esempio n. 2
0
 public function handle()
 {
     $client = new Client();
     $post = DB::table('posts')->where('id', $this->post_id)->first();
     $urls = \Purl\Url::extract($post->content);
     if (config('twitter.oauth_token')) {
         $credentials = array('consumer_key' => config('twitter.id'), 'consumer_secret' => config('twitter.secret'), 'oauth_token' => config('twitter.oauth_token'), 'oauth_token_secret' => config('twitter.oauth_secret'));
         $auth = new SingleUserAuth($credentials, new ArraySerializer());
         $params = ['status' => $post->content];
         $response = $auth->post('statuses/update', $params);
     }
     if (config('linkedin.oauth_token')) {
         try {
             $post_data = array('comment' => $post->content, 'content' => array('description' => $post->content), 'visibility' => array('code' => 'anyone'));
             if (!empty($urls)) {
                 $post_data['content']['submittedUrl'] = trim($urls[0]);
             }
             $request_body = $post_data;
             $linkedin_resource = '/v1/people/~/shares';
             $request_format = 'json';
             $linkedin_params = array('oauth2_access_token' => config('linkedin.oauth_token'), 'format' => $request_format);
             $linkedinurl_info = parse_url('https://api.linkedin.com' . $linkedin_resource);
             if (isset($linkedinurl_info['query'])) {
                 $query = parse_str($linkedinurl_info['query']);
                 $linkedin_params = array_merge($linkedin_params, $query);
             }
             $request_url = 'https://api.linkedin.com' . $linkedinurl_info['path'] . '?' . http_build_query($linkedin_params);
             $request_body = json_encode($request_body);
             $linkedin_response = CurlRequester::requestCURL('POST', $request_url, $request_body, $request_format);
         } catch (Exception $e) {
         }
     }
     if (config('facebook.oauth_token')) {
         try {
             $post_data = array('access_token' => config('facebook.oauth_token'), 'message' => $post->content);
             if (!empty($urls)) {
                 $post_data['link'] = trim($urls[0]);
             }
             $res = $client->post('https://graph.facebook.com/me/feed', array('query' => $post_data));
             $response_body = $res->getBody();
             $response_body = json_decode($response_body, true);
         } catch (Exception $e) {
         }
     }
 }
Esempio n. 3
0
function initTwitterOAuth($credentials, $status)
{
    date_default_timezone_set('UTC');
    /**
     * Instantiate SingleUser
     *
     * For different output formats you can set one of available serializers
     * (Array, Json, Object, Text or a custom one)
     */
    $serializer = new ArraySerializer();
    $auth = new SingleUserAuth($credentials, $serializer);
    /**
     * Now you can post something with the media ids given by Twitter
     *
     * https://dev.twitter.com/rest/reference/post/statuses/update
     */
    $params = array('status' => $status);
    $response = $auth->post('statuses/update', $params);
    return $response;
}
Esempio n. 4
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);
 }
Esempio n. 5
0
require_once '../includes/TwitterOAuth/Serializer/ArraySerializer.php';
require_once '../includes/TwitterOAuth/Exception/TwitterException.php';
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));
Esempio n. 6
0
<?php

require_once '../includes/session.php';
require_once '../includes/db.php';
require_once '../includes/TwitterOAuth/Common/Curl.php';
require_once '../includes/TwitterOAuth/Auth/AuthAbstract.php';
require_once '../includes/TwitterOAuth/Auth/SingleUserAuth.php';
require_once '../includes/TwitterOAuth/Serializer/SerializerInterface.php';
require_once '../includes/TwitterOAuth/Serializer/ArraySerializer.php';
require_once '../includes/TwitterOAuth/Exception/TwitterException.php';
use TwitterOAuth\Auth\SingleUserAuth;
use TwitterOAuth\Serializer\ArraySerializer;
$credentials = array('consumer_key' => 'fxy5RXmMPpvMyMlYWVMP0kqx3', 'consumer_secret' => 'LT29Fbr5OuVPs40OsyiOpFy7mpdqVUNo0zvEuFC59nk0VXRzJu', 'oauth_token' => $_COOKIE['oauth_token'], 'oauth_token_secret' => $_COOKIE['oauth_token_secret']);
$serializer = new ArraySerializer();
$auth = new SingleUserAuth($credentials, $serializer);
if ($_COOKIE['oauth_token'] == $_GET['oauth_token']) {
    $params = array('oauth_verifier' => $_GET['oauth_verifier']);
    $response = $auth->post('oauth/access_token', $params);
    $twitter_user_id = $response['user_id'];
    $screen_name = $response['screen_name'];
    $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();
    if ($row['alreadyRegisteredUser'] == 0) {
        $sql = "INSERT INTO users ( twitter_user_id, screen_name ) VALUES ( :twitter_user_id, :screen_name )";
        $query = $db->prepare($sql);
        $query->execute(array(':twitter_user_id' => $twitter_user_id, ':screen_name' => $screen_name));
    }
    $sql = "select Id from users where twitter_user_id = :twitter_user_id";
    $query = $db->prepare($sql);
Esempio n. 7
0
<?php

require_once 'includes/header.php';
require_once 'includes/TwitterOAuth/Common/Curl.php';
require_once 'includes/TwitterOAuth/Auth/AuthAbstract.php';
require_once 'includes/TwitterOAuth/Auth/SingleUserAuth.php';
require_once 'includes/TwitterOAuth/Serializer/SerializerInterface.php';
require_once 'includes/TwitterOAuth/Serializer/ArraySerializer.php';
require_once 'includes/TwitterOAuth/Exception/TwitterException.php';
use TwitterOAuth\Auth\SingleUserAuth;
use TwitterOAuth\Serializer\ArraySerializer;
$credentials = array('consumer_key' => 'fxy5RXmMPpvMyMlYWVMP0kqx3', 'consumer_secret' => 'LT29Fbr5OuVPs40OsyiOpFy7mpdqVUNo0zvEuFC59nk0VXRzJu');
$serializer = new ArraySerializer();
$auth = new SingleUserAuth($credentials, $serializer);
$params = array('oauth_callback' => rawurldecode('http://162.243.146.56/services/loginCallback.php'));
$loginTwitter = "";
if ($_GET['loginTwitter']) {
    $loginTwitter = $_GET['loginTwitter'];
    if ($loginTwitter == 1) {
        $response = $auth->post('oauth/request_token', $params);
        // echo '<pre>'; print_r($auth->getHeaders()); echo '</pre>';
        // echo '<pre>'; print_r($response['oauth_token']); echo '</pre><hr />';
        // $_COOKIE['oauth_token'] = $response['oauth_token'];
        // $_COOKIE['oauth_token_secret'] = $response['oauth_token_secret'];
        setcookie("oauth_token", $response['oauth_token']);
        setcookie("oauth_token_secret", $response['oauth_token_secret']);
        // $response = $auth->get('auth/authenticate?oauth_token='.$response['oauth_token']);
        header('Location: https://api.twitter.com/oauth/authenticate?oauth_token=' . $response['oauth_token']);
    }
}
?>
Esempio n. 8
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 />';
Esempio n. 9
0
print_r($auth->getHeaders());
echo '</pre>';
echo '<pre class="array">';
print_r($response);
echo '</pre><hr />';
// ==== ==== ==== //
$params = array('owner_screen_name' => 'ricard0per', 'slug' => 'list001');
$response = $auth->post('lists/destroy', $params);
echo '<strong>lists/destroy</strong><br />';
echo '<pre class="array">';
print_r($auth->getHeaders());
echo '</pre>';
echo '<pre class="array">';
print_r($response);
echo '</pre><hr />';
// ==== ==== ==== //
/**
 * Reset Connection Without OAuth Tokens
 */
unset($auth, $credentials['oauth_token'], $credentials['oauth_token_secret']);
$auth = new SingleUserAuth($credentials, new ArraySerializer());
// ==== ==== ==== //
$params = array('oauth_callback' => '');
$response = $auth->post('oauth/request_token', $params);
echo '<strong>oauth/request_token</strong><br />';
echo '<pre class="array">';
print_r($auth->getHeaders());
echo '</pre>';
echo '<pre class="array">';
print_r($response);
echo '</pre><hr />';
Esempio n. 10
0
    
    'headers' => [
    		'oauth_consumer_key' => config('twitter.id'),
    		'oauth_nonce' => $nonce,
    		'oauth_signature' => $signature,
    		'oauth_signature_method' => 'HMAC-SHA1',
    		'oauth_timestamp' => time(),
    		'oauth_token' => config('twitter.oauth_token'),
    		'oauth_version' => '1.0'
    	],
    	'form' => [
    		'status' => $content
    	]
    	]
    	);
    return $client->getBody();
    */
    /*
    $twitter = new Twitter(config('twitter.id'), config('twitter.secret'));
    $twitter->setOAuthToken(config('twitter.oauth_token'));
    $twitter->setOAuthTokenSecret(config('twitter.oauth_secret'));
    
    $response = $twitter->statusesUpdate('Running the tests.. 私のさえずりを設定する '. time());
    return $response;
    */
    $credentials = array('consumer_key' => config('twitter.id'), 'consumer_secret' => config('twitter.secret'), 'oauth_token' => config('twitter.oauth_token'), 'oauth_token_secret' => config('twitter.oauth_secret'));
    $auth = new SingleUserAuth($credentials, new ArraySerializer());
    $params = ['status' => 'Running the tests.. 私のさえずりを設定する'];
    $response = $auth->post('statuses/update', $params);
    return $response;
});
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());
/**
 * Get cURL Default Options
 */
$curlOptions = $auth->getCurl()->getOptions();
echo '[ Get cURL Default Options ]<pre>';
var_dump($curlOptions);
echo '</pre><hr />';
/**
 * Customize cURL Options
 *
 *   - Change Certs to PHP defaults
 *   - Set timeout and connection timeout to 120 seconds
 */
unset($curlOptions[CURLOPT_CAINFO]);
$curlOptions[CURLOPT_TIMEOUT] = $curlOptions[CURLOPT_CONNECTTIMEOUT] = 120;
/**
 * Array with the OAuth tokens provided by Twitter
 *   - consumer_key        Twitter API key
 *   - consumer_secret     Twitter API secret
 *   - oauth_token         Twitter Access token
 *   - oauth_token_secret  Twitter Access token secret
 */
$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)
 */
$serializer = new ArraySerializer();
$auth = new SingleUserAuth($credentials, $serializer);
/**
 * To post something with media, first you need to upload some media
 * and get the ids given by Twitter
 *
 * https://dev.twitter.com/rest/public/uploading-media-multiple-photos
 */
$response = $auth->postMedia('media/upload', './photo1.jpeg');
$media_ids[] = $response['media_id'];
$response = $auth->postMedia('media/upload', './photo2.jpg');
$media_ids[] = $response['media_id'];
$response = $auth->postMedia('media/upload', './photo3.png');
$media_ids[] = $response['media_id'];
/**
 * Now you can post something with the media ids given by Twitter
 *