当前位置: 首页>>代码示例>>PHP>>正文


PHP TwitterOAuth类代码示例

本文整理汇总了PHP中TwitterOAuth的典型用法代码示例。如果您正苦于以下问题:PHP TwitterOAuth类的具体用法?PHP TwitterOAuth怎么用?PHP TwitterOAuth使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TwitterOAuth类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: Medieteknik_Save_Token

function Medieteknik_Save_Token()
{
    //assume we have been authorized and returned
    //first check if we have a logged in user
    //äckliga wordpress vill att man gör såhär
    global $user_ID;
    get_currentuserinfo();
    if (!$user_ID) {
        die('Du är inte inloggad i wordpress. LOGGA IN FFS!!!!');
    }
    //get our temporary token
    $token = $_SESSION['oauth_token'];
    $secret = $_SESSION['oauth_token_secret'];
    //kolla att vi faktiskt har en token
    if (!$token || !$secret) {
        die('Kunde inte hitta en sparad token. Gör om gör rätt!');
    }
    //request a permanent token
    $oauth = new TwitterOAuth($token, $secret);
    $new_token = $oauth->access_token();
    //check our reply
    if (!$new_token['oauth_token'] || !$new_token['oauth_token_secret']) {
        die('Du blev inte autoriserad. Prova igen?');
    }
    //insert token and secret into the usermeta database
    update_usermeta($user_ID, 'twitter_token', $new_token['oauth_token']);
    update_usermeta($user_ID, 'twitter_token_secret', $new_token['oauth_token_secret']);
    //echo 'Välkommen ' . $new_token['screen_name'];
    //istället redirecta till index
    header('location: index.php');
}
开发者ID:jakbob,项目名称:medieteknik.org,代码行数:31,代码来源:twitter_save_token.php

示例2: Medieteknik_post_tweet

function Medieteknik_post_tweet($tweet, $hashtag)
{
    //get current user
    global $user_ID;
    get_currentuserinfo();
    //get the saved token for this user
    $token = get_usermeta($user_ID, 'twitter_token');
    $secret = get_usermeta($user_ID, 'twitter_token_secret');
    $oauth = new TwitterOAuth($token, $secret);
    $url = 'http://api.twitter.com/1/statuses/update.xml';
    if ($hashtag && strpos(strtolower($tweet), '#medieteknik') == false) {
        //add the hashtag
        $tweet = rtrim($tweet) . ' #medieteknik';
    }
    $params = array('status' => $tweet);
    $reply = $oauth->oauth_request($url, 'POST', $params);
    //Check our request came out ok
    if ($reply['status'] != 200) {
        if ($reply['status'] == 403) {
            die('Twitter tillåter endast 150 statusuppdateringar i timmen. Försök igen senare');
        } else {
            die('Något är galet med twitter. Försök igen senare eller kontakta sidansvarig');
        }
    }
    header('location: index.php');
}
开发者ID:jakbob,项目名称:medieteknik.org,代码行数:26,代码来源:twitter_post_status.php

示例3: post

 public static function post($user, $text)
 {
     $culture = $user->getCulture();
     $profile = $user->getGuardUser()->getProfile();
     $connection = new TwitterOAuth(sfConfig::get("app_twitter_api_consumer_key_{$culture}"), sfConfig::get("app_twitter_api_consumer_secret_{$culture}"), $profile->getTwOauthToken(), $profile->getTwOauthTokenSecret());
     $connection->post('statuses/update', array('status' => $text));
 }
开发者ID:voota,项目名称:voota,代码行数:7,代码来源:TwitterManager.class.php

示例4: post

 function post($message)
 {
     error_reporting(0);
     $acces = array('consumer_key' => $this->auth['consumer_key'], 'consumer_secret' => $this->auth['consumer_secret'], 'access_token' => $this->auth['access_token'], 'access_secret' => $this->auth['access_secret']);
     $twitter = new TwitterOAuth($acces['consumer_key'], $acces['consumer_secret'], $acces['access_token'], $acces['access_secret']);
     $response = $twitter->post('statuses/update', array('status' => $message));
 }
开发者ID:rifaiaja,项目名称:orpsystem,代码行数:7,代码来源:twitter_model.php

示例5: push

 public function push($Account, $TwitterStatus)
 {
     $NGPushIni = eZINI::instance('ngpush.ini');
     $Token = self::getToken($Account);
     if (!$Token) {
         self::requestToken($Account);
         $Token = self::getToken($Account);
     }
     if ($Token) {
         $tokenCredentials = explode('%%%', $Token);
         $connection = new TwitterOAuth($NGPushIni->variable($Account, 'ConsumerKey'), $NGPushIni->variable($Account, 'ConsumerSecret'), $tokenCredentials[0], $tokenCredentials[1]);
         $connection->host = "https://api.twitter.com/1.1/";
         $TwitterResponse = $connection->post('statuses/update', array('status' => $TwitterStatus));
         self::$response['response'] = $TwitterResponse;
         //Let's analyize some Twitter JSON response (lots of data but no clear structure and no status)
         if ($TwitterResponse->error) {
             self::$response['status'] = 'error';
             self::$response['messages'][] = $TwitterResponse->error;
         } elseif ($TwitterResponse->errors) {
             self::$response['status'] = 'error';
             foreach ($TwitterResponse->errors as $TwitterResponseError) {
                 self::$response['messages'][] = $TwitterResponseError->message;
             }
         } else {
             self::$response['status'] = 'success';
             if ($TwitterResponse->created_at) {
                 self::$response['messages'][] = 'Status is published!';
             }
         }
     } else {
         self::$response['status'] = 'error';
         self::$response['messages'][] = 'You need access token to use this application with Twitter.';
     }
     return self::$response;
 }
开发者ID:netgen,项目名称:ngpush,代码行数:35,代码来源:ngpush_twitter_status.php

示例6: xAction

 /**
  * @Route("/souphpsp/x")
  */
 public function xAction()
 {
     $oauth = new \TwitterOAuth('qPLsh4YhO2Ui8KmM6vRtw', 'CbtjJPSD1yxxJfbbr4TPKX7K0UCExnffk5Qg', '18179550-Z6V17Ly1tvyOEiqCjuq1NfenI71FacvFrlqYT8Bqb', 'CkS51WZMERauimVxZBOxVQVLtBeDzIZCFLzCQpGzlg');
     $res = $oauth->post('http://api.twitter.com/1/direct_messages/new.json', array('screen_name' => 'rdohms', 'text' => 'mytext'));
     var_dump($res);
     return new \Symfony\Component\HttpFoundation\Response();
 }
开发者ID:rdohms,项目名称:PHPSP-Promos,代码行数:10,代码来源:DefaultController.php

示例7: IOAgetTweets

/**
 * Twitter Shortcode using aouth
 */
function IOAgetTweets($count = 20, $username = false, $ioa_options = false)
{
    global $super_options;
    require_once HPATH . '/lib/twitteroauth/twitteroauth.php';
    $settings = array('oauth_access_token' => $super_options[SN . '_twitter_token'], 'oauth_access_token_secret' => $super_options[SN . '_twitter_secret_token'], 'consumer_key' => $super_options[SN . '_twitter_key'], 'consumer_secret' => $super_options[SN . '_twitter_secret_key']);
    $data = array();
    if (get_transient(SN . '_ioa_tweets')) {
        $data = get_transient(SN . '_ioa_tweets');
    } else {
        $connection = new TwitterOAuth($super_options[SN . '_twitter_key'], $super_options[SN . '_twitter_secret_key'], $super_options[SN . '_twitter_token'], $super_options[SN . '_twitter_secret_token']);
        $data = $connection->get('statuses/user_timeline');
        set_transient(SN . '_ioa_tweets', $data, 60 * 60 * 3);
    }
    $i = 0;
    $filter_array = array();
    if (!isset($data->errors)) {
        foreach ($data as $d) {
            if ($i > $count) {
                break;
            }
            $filter_array[] = array("text" => $d->text);
            $i++;
        }
    }
    return $filter_array;
}
开发者ID:severnrescue,项目名称:web,代码行数:29,代码来源:shortcodes.php

示例8: getUserAccessToken

 function getUserAccessToken()
 {
     $session_access_token = $this->constructSessionVariableName("access_token");
     $token = NULL;
     if (isset($_SESSION[$session_access_token])) {
         $token = $_SESSION[$session_access_token];
         if (!$token || !isset($token["oauth_token"])) {
             unset($_SESSION[$session_access_token]);
         }
     }
     if (!$token) {
         $session_request_token = $this->constructSessionVariableName("oauth_request_token");
         $session_request_token_secret = $this->constructSessionVariableName("oauth_request_token_secret");
         if (isset($_SESSION[$session_request_token]) && isset($_SESSION[$session_request_token_secret])) {
             $to = new TwitterOAuth($this->getTwitter()->consumer->key, $this->getTwitter()->consumer->secret, $_SESSION[$session_request_token], $_SESSION[$session_request_token_secret]);
             $token = $to->getAccessToken($_REQUEST['oauth_verifier']);
             if (!$token || !isset($token["oauth_token"])) {
                 unset($_SESSION[$session_request_token]);
                 unset($_SESSION[$session_request_token_secret]);
             } else {
                 $session_var_name = $this->constructSessionVariableName("access_token");
                 $_SESSION[$session_var_name] = $token;
             }
         }
     }
     return $token;
 }
开发者ID:ateliee,项目名称:php_lib,代码行数:27,代码来源:class_twitter.php

示例9: index

 function index()
 {
     require APPPATH . 'modules/twitter/libraries/twitteroauth.php';
     /* If the oauth_token is old redirect to the connect page. */
     if ($this->input->get('oauth_token') && $this->session->userdata('twitter_oauth_token') !== $this->input->get('oauth_token')) {
         return redirect('admincp/twitter');
     }
     /* Create TwitteroAuth object with app key/secret and token key/secret from default phase */
     $connection = new TwitterOAuth(setting('twitter_consumer_key'), setting('twitter_consumer_secret'), $this->session->userdata('twitter_oauth_token'), $this->session->userdata('twitter_oauth_token_secret'));
     /* Request access tokens from twitter */
     $access_token = $connection->getAccessToken($this->input->get('oauth_verifier'));
     /* Save the access tokens. Normally these would be saved in a database for future use. */
     $this->settings_model->update_setting('twitter_oauth_token', $access_token['oauth_token']);
     $this->settings_model->update_setting('twitter_oauth_token_secret', $access_token['oauth_token_secret']);
     /* Remove no longer needed request tokens */
     $this->session->unset_userdata('twitter_oauth_token');
     $this->session->unset_userdata('twitter_oauth_token_secret');
     /* If HTTP response is 200 continue otherwise send to connect page to retry */
     if (200 == $connection->http_code) {
         $this->notices->SetNotice('OAuthorization retrieved successfully.');
         return redirect('admincp/twitter');
     } else {
         $this->notices->SetError('Error making connection in OAuth callback.');
         return redirect('admincp/twitter');
     }
 }
开发者ID:josev814,项目名称:hero,代码行数:26,代码来源:oauth_callback.php

示例10: post_on_behalf_of

function post_on_behalf_of($user, $message) {
	if (!empty($user['tw_oauth_token']) && !empty($user['tw_oauth_token_secret'])) {
		$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $user['tw_oauth_token'], $user['tw_oauth_token_secret']);
		$resp = $connection->post('statuses/update', array('status' => $message));
		return (200 == $connection->http_code);
	}
}
开发者ID:njoubert,项目名称:SXSW_Website,代码行数:7,代码来源:include.php

示例11: twiget_get_tweets

/**
 * Authenticate to Twitter using oAuth, and retrieve tweets
 */
function twiget_get_tweets()
{
    require_once TWIGET_PLUGIN_PATH . '/lib/twitteroauth.php';
    $twiget_options = get_option('twiget_options');
    $defaults = array('user_id' => NULL, 'screen_name' => NULL, 'since_id' => NULL, 'count' => 5, 'max_id' => NULL, 'trim_user' => NULL, 'exclude_replies' => NULL, 'include_rts' => NULL, 'contributor_details' => NULL, 'widget_id' => NULL);
    $options = array_intersect_key(array_merge($defaults, $_POST), $defaults);
    $cache_period = $twiget_options['cache_period'] ? $twiget_options['cache_period'] : ceil(15 * 60 / 180 * twiget_count_instances());
    $cache_disabled = $cache_period == 0 ? true : false;
    if (!$cache_disabled) {
        $tweets = get_transient('tweets-' . $options['widget_id']);
    } else {
        $tweets = false;
    }
    if ($tweets === false) {
        $consumerkey = $twiget_options['consumer_key'];
        $consumersecret = $twiget_options['consumer_secret'];
        $accesstoken = $twiget_options['access_token'];
        $accesstokensecret = $twiget_options['access_token_secret'];
        session_start();
        $connection = new TwitterOAuth($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);
        $tweets = $connection->get('https://api.twitter.com/1.1/statuses/user_timeline.json?' . http_build_query($options));
        $tweets = json_encode($tweets);
        if (!$cache_disabled) {
            set_transient('tweets-' . $options['widget_id'], $tweets, $cache_period);
        }
    }
    echo $tweets;
    exit;
}
开发者ID:uwmadisoncals,项目名称:Cluster-Plugins,代码行数:32,代码来源:get-tweets.php

示例12: testIDsList

 function testIDsList()
 {
     global $THINKTANK_CFG;
     $to = new TwitterOAuth('', '', '', '');
     $result = $to->oAuthRequest('https://twitter.com/followers/ids.xml', array(), 'GET');
     $r = array();
     $r["id"] = 0;
     $r['network_username'] = 'user';
     $r['network_user_id'] = 0;
     $r['last_status_id'] = 0;
     $r['last_page_fetched_replies'] = 0;
     $r['last_page_fetched_tweets'] = 0;
     $r['total_posts_in_system'] = 0;
     $r['total_replies_in_system'] = 0;
     $r['total_follows_in_system'] = 0;
     $r['total_users_in_system'] = 0;
     $r['is_archive_loaded_replies'] = 0;
     $r['is_archive_loaded_follows'] = 0;
     $r['crawler_last_run'] = '1/1/2007';
     $r['earliest_reply_in_system'] = 0;
     $r['api_calls_to_leave_unmade_per_minute'] = 5;
     $r['avg_replies_per_day'] = 0;
     $r['is_public'] = 1;
     $r['is_active'] = 1;
     $r['network'] = 'twitter';
     $i = new Instance($r);
     $api = new CrawlerTwitterAPIAccessorOAuth('111', '222', $THINKTANK_CFG['oauth_consumer_key'], $THINKTANK_CFG['oauth_consumer_secret'], $i, $THINKTANK_CFG['archive_limit']);
     $users = $api->parseXML($result);
     $next_cursor = $api->getNextCursor();
     //echo 'Next cursor is ' . $next_cursor;
     $this->assertTrue($next_cursor == '1326272872342936860');
 }
开发者ID:harjitdotsingh,项目名称:thinktank,代码行数:32,代码来源:twitterapiaccessoroauth_test.php

示例13: twitter_oauth_login_test

function twitter_oauth_login_test(&$vars)
{
    extract($vars);
    $success = false;
    $TwitterUser =& $db->model('TwitterUser');
    $tu = $TwitterUser->find_by(array('profile_id' => get_profile_id()), 1);
    if ($tu) {
        // http://abrah.am
        if (!class_exists('oauthexception')) {
            lib_include('twitteroauth');
        }
        $key = $tu->oauth_key;
        $secret = $tu->oauth_secret;
        $consumer_key = environment('twitterKey');
        $consumer_secret = environment('twitterSecret');
        $to = new TwitterOAuth($consumer_key, $consumer_secret, $tu->oauth_key, $tu->oauth_secret);
        $timelineurl = 'https://twitter.com/statuses/friends_timeline.atom';
        $response = $to->OAuthRequest($timelineurl, array(), 'GET');
        if (strpos($response, '<subtitle>')) {
            $success = true;
        }
    }
    if ($success) {
        echo 1;
    } else {
        echo 0;
    }
    exit;
}
开发者ID:Br3nda,项目名称:openmicroblogger,代码行数:29,代码来源:ak_twitter.php

示例14: getContent

 public function getContent()
 {
     try {
         $dataKey = self::CONTENT;
         $content = $this->getData($dataKey);
         if ($content === false) {
             require_once 'Twitter/twitteroauth.php';
             $consumer_key = $this->config->getTwitterConsummerKey();
             $consumer_secret = $this->config->getTwitterConsummerSecret();
             $oauth_token = $this->config->getTwitterAuthToken();
             $oauth_token_secret = $this->config->getTwitterAuthTokenSecret();
             /* Create a TwitterOauth object with consumer/user tokens. */
             $connection = new \TwitterOAuth($consumer_key, $consumer_secret, $oauth_token, $oauth_token_secret);
             $user = "Cherbouquin";
             /* Nom d'utilisateur sur Twitter */
             $count = 10;
             /* Nombre de message à afficher */
             $query = 'https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=' . $user . '&count=' . $count;
             // Your Twitter API query
             $content = $connection->get($query);
             $this->setData($dataKey, $content);
         }
         return $content;
     } catch (\Exception $exc) {
         $this->logException(get_class(), __FUNCTION__, $exc);
     }
 }
开发者ID:berliozd,项目名称:cherbouquin,代码行数:27,代码来源:TwitterSvc.php

示例15: ie_api_twitter_login

/**
 * Method for Twitter login
 */
function ie_api_twitter_login()
{
    // Test user is logged in
    if (!iewp_api_user_is_logged_in()) {
        die('Error: please sign in');
    }
    // Twitter app credentials
    $consumer_key = trim(get_option('iewp_api_twitterapp_consumer_key', ''));
    $consumer_secret = trim(get_option('iewp_api_twitterapp_consumer_secret', ''));
    $callback_url = site_url('wp-json/ie-api/twitter-callback');
    // Test app creds have been set
    if ($consumer_key == '' || $consumer_secret == '') {
        die('Error: invalid twitter app credentials');
    }
    // Get a request token
    $connection = new TwitterOAuth($consumer_key, $consumer_secret);
    $request_token = $connection->getRequestToken($callback_url);
    // Store the request token for use in callback
    $user_id = iewp_api_id_from_hash();
    update_user_meta($user_id, 'twitter_oauth_token', $request_token['oauth_token']);
    update_user_meta($user_id, 'twitter_oauth_token_secret', $request_token['oauth_token_secret']);
    // Redirect to Twitter app approval page
    $redirect_url = $connection->getAuthorizeURL($request_token);
    wp_redirect($redirect_url);
    exit;
}
开发者ID:corenominal,项目名称:internet.engineering-wp-api,代码行数:29,代码来源:twitter_login.php


注:本文中的TwitterOAuth类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。