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


PHP TwitterOAuth::getRequestToken方法代码示例

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


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

示例1: 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

示例2: authTwitter

 protected function authTwitter($save_name)
 {
     $config = $this->config;
     $conn = new TwitterOAuth($config['consumer_key'], $config['consumer_secret']);
     $request_token = $conn->getRequestToken();
     if ($request_token === false || $conn->lastStatusCode() != 200) {
         throw new RuntimeException("Error fetching Twitter auth token: Status code " . $conn->lastStatusCode() . '; ' . $conn->http_error);
     }
     $url = $conn->getAuthorizeURL($request_token);
     // Automatically send the user to the auth page.
     $ui = new UI();
     $ui->openBrowser($url);
     $pin = $ui->readline("Please visit {$url} then type the pin number: ");
     $conn = new TwitterOAuth($config['consumer_key'], $config['consumer_secret'], $request_token['oauth_token'], $request_token['oauth_token_secret']);
     $access_token = $conn->getAccessToken($pin);
     if ($access_token === false || $conn->lastStatusCode() != 200) {
         throw new RuntimeException("Error fetching Twitter access token: Status code " . $conn->lastStatusCode() . '; ' . $conn->http_error);
     }
     $this->config['oauth_token'] = $access_token['oauth_token'];
     $this->config['oauth_token_secret'] = $access_token['oauth_token_secret'];
     echo "Your Twitter token is " . $access_token['oauth_token'] . "\n";
     echo "Your Twitter token secret is " . $access_token['oauth_token_secret'] . "\n";
     echo "(Written to twitter-{$save_name}.txt)\n";
     if (file_put_contents("twitter-{$save_name}.txt", $access_token['oauth_token'] . "\n" . $access_token['oauth_token_secret'])) {
         return;
     }
     throw new RuntimeException("Failed to save oauth token to twitter-{$save_name}.txt");
 }
开发者ID:rabyunghwa,项目名称:sslscrobbler,代码行数:28,代码来源:TwitterPlugin.php

示例3: twitter_init

/**
 * Handles twitter authorization (redirects to twitter url if user clicked on "twitter" ion
 *
 * @return void
 */
function twitter_init()
{
    global $wpdb, $user_identity, $user_ID, $table_prefix, $id, $up_options;
    if ((empty($_GET['l']) || $_GET['l'] != 'tw' || is_user_logged_in()) && !isset($_GET['oauth_token']) && !isset($_GET['oauth_verifier'])) {
        return;
    }
    $twitter_consumer_key = $up_options->twitter_consumer_key;
    //get_option("qya_textTwitterConsumerKey");
    $twitter_consumer_secret = $up_options->twitter_consumer_secret;
    //get_option("qya_textTwitterConsumerSecret");
    if (isset($_GET['oauth_token']) && isset($_GET['oauth_verifier'])) {
        return authorize_twitter_user($_GET['oauth_token'], $_GET['oauth_verifier']);
    }
    if (empty($twitter_consumer_key) || empty($twitter_consumer_secret)) {
        return;
    }
    $connection = new TwitterOAuth($twitter_consumer_key, $twitter_consumer_secret);
    $oauth_callback = get_option("siteurl");
    /* Get temporary credentials. */
    $request_token = $connection->getRequestToken($oauth_callback);
    $token = $request_token['oauth_token'];
    $_SESSION['twitter_token'] = $request_token;
    /* If last connection failed don't display authorization link. */
    switch ($connection->http_code) {
        case 200:
            /* Build authorize URL and redirect user to Twitter. */
            $url = $connection->getAuthorizeURL($token);
            header('Location: ' . $url);
            break;
        default:
            /* Show notification if something went wrong. */
            echo 'Could not connect to Twitter. Refresh the page or try again later.';
    }
    exit;
}
开发者ID:gp6shc,项目名称:aok,代码行数:40,代码来源:twitter-new.php

示例4: loginLink

 static function loginLink()
 {
     $connection = new TwitterOAuth(WRA_CONF::$twiappid, WRA_CONF::$twiappsecret);
     $temporary_credentials = $connection->getRequestToken(WRA_CONF::$twiauthlink);
     $redirect_url = $connection->getAuthorizeURL($temporary_credentials);
     return $redirect_url;
 }
开发者ID:sergiovelayos,项目名称:liveuamap,代码行数:7,代码来源:wra_twitter.php

示例5: getRedirectUri

 /**
  * This method is used to process the first part of authentication workflow, before redirect
  *
  * @return array Array with status and redirect URI
  */
 public function getRedirectUri()
 {
     $ngConnectINI = eZINI::instance('ngconnect.ini');
     $http = eZHTTPTool::instance();
     $consumerKey = trim($ngConnectINI->variable('LoginMethod_twitter', 'AppConsumerKey'));
     $consumerSecret = trim($ngConnectINI->variable('LoginMethod_twitter', 'AppConsumerSecret'));
     if (empty($consumerKey) || empty($consumerSecret)) {
         return array('status' => 'error', 'message' => 'Consumer key or consumer secret undefined.');
     }
     $callbackUri = self::CALLBACK_URI_PART;
     $loginWindowType = trim($ngConnectINI->variable('ngconnect', 'LoginWindowType'));
     if ($loginWindowType == 'popup') {
         $callbackUri = '/layout/set/ngconnect' . self::CALLBACK_URI_PART;
     }
     $state = md5(session_id() . (string) time());
     $http->setSessionVariable('NGConnectOAuthState', $state);
     $callbackUri .= '?state=' . $state;
     eZURI::transformURI($callbackUri, false, 'full');
     $connection = new TwitterOAuth($consumerKey, $consumerSecret);
     $connection->host = self::TWITTER_API_URI;
     $tempCredentials = $connection->getRequestToken($callbackUri);
     $redirectUri = $connection->getAuthorizeURL($tempCredentials);
     if (!$redirectUri) {
         return array('status' => 'error', 'message' => 'Invalid redirection URI.');
     }
     $http->setSessionVariable('NGConnectOAuthToken', $tempCredentials['oauth_token']);
     $http->setSessionVariable('NGConnectOAuthTokenSecret', $tempCredentials['oauth_token_secret']);
     return array('status' => 'success', 'redirect_uri' => $redirectUri);
 }
开发者ID:netgen,项目名称:ngconnect,代码行数:34,代码来源:ngconnectauthtwitter.php

示例6: _loginAction

 protected function _loginAction()
 {
     $option = $this->_getProviderOption();
     // セッションにアクセストークンがなかったらloginページに飛ぶ
     // サインインしていてもログイン状態でなければSESSIONを消す
     $pengin =& Pengin::getInstance();
     if ($pengin->cms->isUser() == false) {
         unset($_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
     }
     if (isset($_SESSION['oauth_token']) == true and isset($_SESSION['oauth_token_secret']) == true) {
         if ($_SESSION['oauth_token'] === NULL && $_SESSION['oauth_token_secret'] === NULL) {
             $tokenExist = false;
         } else {
             $tokenExist = true;
         }
     } else {
         $tokenExist = false;
     }
     if ($tokenExist == false) {
         // OAuthオブジェクト生成
         $to = new TwitterOAuth($option['key'], $option['secret']);
         // callbackURLを指定してRequest tokenを取得
         $tok = $to->getRequestToken($this->connect);
         // セッションに保存
         $_SESSION['request_token'] = $token = $tok['oauth_token'];
         $_SESSION['request_token_secret'] = $tok['oauth_token_secret'];
         // サインインするためのURLを取得
         $url = $to->getAuthorizeURL($token);
         header("location:" . $url);
         die;
     } else {
         //サインインしていればヘッダーを出力
         //include("user_header.php");
     }
 }
开发者ID:nouphet,项目名称:xoops-tpSocialMedia,代码行数:35,代码来源:Twitter.php

示例7: requestToken

 public function requestToken($Account)
 {
     $NGPushIni = eZINI::instance('ngpush.ini');
     $ConsumerKey = $NGPushIni->variable($Account, 'ConsumerKey');
     $ConsumerSecret = $NGPushIni->variable($Account, 'ConsumerSecret');
     $AccessToken = $NGPushIni->variable($Account, 'AccessToken');
     $AccessTokenSecret = $NGPushIni->variable($Account, 'AccessTokenSecret');
     // If access tokens are given
     if ($AccessToken && $AccessTokenSecret) {
         // Save request signing tokens to cache
         ngPushBase::save_token($Account, $AccessToken, 'request_sign_oauth_token');
         ngPushBase::save_token($Account, $AccessTokenSecret, 'request_sign_oauth_token_secret');
         ngPushBase::save_token($Account, $AccessToken . '%%%' . $AccessTokenSecret, 'main_token');
     } else {
         $connection = new TwitterOAuth($ConsumerKey, $ConsumerSecret);
         $connection->host = "https://api.twitter.com/1.1/";
         $AdministrationUrl = '/';
         eZURI::transformURI($AdministrationUrl, false, 'full');
         $AdministrationUrl = base64_encode($AdministrationUrl);
         $SettingsBlock = base64_encode($Account);
         $temporary_credentials = $connection->getRequestToken('http://' . $NGPushIni->variable('PushNodeSettings', 'ConnectURL') . '/redirect.php/' . $AdministrationUrl . '/' . $SettingsBlock . '?case=twitter');
         // Save request signing tokens to cache
         ngPushBase::save_token($Account, $temporary_credentials['oauth_token'], 'request_sign_oauth_token');
         ngPushBase::save_token($Account, $temporary_credentials['oauth_token_secret'], 'request_sign_oauth_token_secret');
         $redirect_url = $connection->getAuthorizeURL($temporary_credentials, FALSE);
         self::$response['RequestPermissionsUrl'] = $redirect_url;
     }
 }
开发者ID:netgen,项目名称:ngpush,代码行数:28,代码来源:ngpush_twitter_base.php

示例8: update

 function update($new_instance, $old_instance)
 {
     $instance = $old_instance;
     $tb_o = get_option('tweet-blender');
     $errors = array();
     // check to make sure we have oAuth token
     if (!$tb_o['oauth_access_token']) {
         // Create TwitterOAuth object and get request token
         $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
         // Get request token
         $request_token = $connection->getRequestToken(get_bloginfo('url') . '/' . PLUGINDIR . "/tweet-blender/lib/twitteroauth/callback.php");
         if ($connection->http_code == 200) {
             // Save request token to session
             $tb_o['oauth_token'] = $token = $request_token['oauth_token'];
             $tb_o['oauth_token_secret'] = $request_token['oauth_token_secret'];
             update_option('tweet-blender', $tb_o);
             $errors[] = __("Twitter API v1.1 requires authentication", 'tweetblender') . " <a href='javascript:tAuth(\"" . $connection->getAuthorizeURL($token) . "\")' title=" . __('Authorize Access', 'tweetblender') . ">" . __('Use your Twitter account to login', 'tweetblender') . "</a>.";
         } else {
             $errors[] = __("Twitter oAuth is not possible at this time.", 'tweetblender') . "<!--" . $connection->last_api_call . "-->";
         }
     }
     if (sizeof($errors) == 0) {
         $this->message = __('Settings saved', 'tweetblender');
         $instance['title'] = trim(strip_tags($new_instance['title']));
         $instance['widget_refresh_rate'] = $new_instance['widget_refresh_rate'];
         $instance['widget_tweets_num'] = $new_instance['widget_tweets_num'];
         return $instance;
     } else {
         if (sizeof($errors) > 0) {
             $this->error .= join(', ', $errors);
         }
         $this->bad_input = $new_instance;
         return false;
     }
 }
开发者ID:alditayurio,项目名称:mhsd_dettol,代码行数:35,代码来源:widget-tags.php

示例9: initComment

 public static function initComment($api)
 {
     session_start();
     $options = Typecho_Widget::widget('Widget_Options');
     $config = $options->plugin('ConnectToTwitter');
     //发送请求到twitter
     if (isset($api->request->connect_to_twitter)) {
         $to = new TwitterOAuth($config->consumerKey, $config->consumerSecret);
         $tok = $to->getRequestToken();
         Typecho_Cookie::set('oauth_request_token', $tok['oauth_token']);
         Typecho_Cookie::set('oauth_request_token_secret', $tok['oauth_token_secret']);
         /* Build the authorization URL */
         $request_link = $to->getAuthorizeURL($tok['oauth_token']);
         header('Location:' . $request_link);
     }
     //从twitter返回
     if (isset($api->request->oauth_token)) {
         if (Typecho_Cookie::get('oauth_request_token') && Typecho_Cookie::get('oauth_request_token_secret')) {
             $to = new TwitterOAuth($config->consumerKey, $config->consumerSecret, Typecho_Cookie::get('oauth_request_token'), Typecho_Cookie::get('oauth_request_token_secret'));
             $tok = $to->getAccessToken();
             Typecho_Cookie::set('oauth_access_token', $tok['oauth_token'], time() + 60 * 60 * 24 * 30);
             Typecho_Cookie::set('oauth_access_token_secret', $tok['oauth_token_secret'], time() + 60 * 60 * 24 * 30);
             $info_json = $to->OAuthRequest('https://twitter.com/account/verify_credentials.json', array(), 'GET');
             $info = Typecho_Json::decode($info_json, true);
             self::twitterLogin($info, $api);
         }
     }
 }
开发者ID:luobenyu,项目名称:plugins,代码行数:28,代码来源:Plugin.php

示例10: authControl

 public function authControl()
 {
     $config = Config::getInstance();
     Loader::definePathConstants();
     $this->setViewTemplate(THINKUP_WEBAPP_PATH . 'plugins/twitter/view/twitter.account.index.tpl');
     $this->view_mgr->addHelp('twitter', 'userguide/settings/plugins/twitter/index');
     $instance_dao = DAOFactory::getDAO('InstanceDAO');
     // get plugin option values if defined...
     $plugin_options = $this->getPluginOptions();
     $oauth_consumer_key = $this->getPluginOption('oauth_consumer_key');
     $oauth_consumer_secret = $this->getPluginOption('oauth_consumer_secret');
     $archive_limit = $this->getPluginOption('archive_limit');
     $num_twitter_errors = $this->getPluginOption('num_twitter_errors');
     $this->addToView('twitter_app_name', "ThinkUp " . $_SERVER['SERVER_NAME']);
     $this->addToView('thinkup_site_url', Utils::getApplicationURL(true));
     $plugin = new TwitterPlugin();
     if ($plugin->isConfigured()) {
         $this->addToView('is_configured', true);
         $owner_instances = $instance_dao->getByOwnerAndNetwork($this->owner, 'twitter');
         $this->addToView('owner_instances', $owner_instances);
         if (isset($this->owner) && $this->owner->isMemberAtAnyLevel()) {
             if ($this->owner->isMemberLevel()) {
                 if (sizeof($owner_instances) > 0) {
                     $this->do_show_add_button = false;
                     $this->addInfoMessage("To connect another Twitter account to ThinkUp, upgrade your membership.", 'membership_cap');
                 }
             }
         }
         if (isset($_GET['oauth_token']) || $this->do_show_add_button) {
             $twitter_oauth = new TwitterOAuth($oauth_consumer_key, $oauth_consumer_secret);
             /* Request tokens from twitter */
             $token_array = $twitter_oauth->getRequestToken(Utils::getApplicationURL(true) . "account/?p=twitter");
             if (isset($token_array['oauth_token']) || isset($_SESSION["MODE"]) && $_SESSION["MODE"] == "TESTS" || getenv("MODE") == "TESTS") {
                 //testing
                 $token = $token_array['oauth_token'];
                 SessionCache::put('oauth_request_token_secret', $token_array['oauth_token_secret']);
                 if (isset($_GET['oauth_token'])) {
                     self::addAuthorizedUser($oauth_consumer_key, $oauth_consumer_secret, $num_twitter_errors);
                 }
                 if ($this->do_show_add_button) {
                     /* Build the authorization URL */
                     $oauthorize_link = $twitter_oauth->getAuthorizeURL($token);
                     $this->addToView('oauthorize_link', $oauthorize_link);
                 }
             } else {
                 //set error message here
                 $this->addErrorMessage("Unable to obtain OAuth tokens from Twitter. Please double-check the consumer key and secret " . "are correct.", "setup");
                 $oauthorize_link = '';
                 $this->addToView('is_configured', false);
             }
         }
     } else {
         $this->addInfoMessage('Please complete plugin setup to start using it.', 'setup');
         $this->addToView('is_configured', false);
     }
     // add plugin options from
     $this->addOptionForm();
     return $this->generateView();
 }
开发者ID:nagyistoce,项目名称:ThinkUp,代码行数:59,代码来源:class.TwitterPluginConfigurationController.php

示例11: newOAuthToken

 /**
  * @param url http://localhost/'.$this->Ctrl->getConf('site.url').'/app/conf.twitter'
  */
 function newOAuthToken($url = '.')
 {
     $connection = new TwitterOAuth($this->con_key, $this->con_secret);
     $request_token = $connection->getRequestToken($url);
     $token = $request_token['oauth_token'];
     $secret = $request_token['oauth_token_secret'];
     return array($token, $secret);
 }
开发者ID:kurari,项目名称:Nyaa-System,代码行数:11,代码来源:twitter.class.php

示例12: set_temporary_credentials

 /**
  * Used to set temporary credentials in Session
  * Get this credentials from Twitter API library
  *
  * @access public
  * @return string
  */
 public function set_temporary_credentials()
 {
     $connection = new TwitterOAuth($this->_config['consumer_key'], $this->_config['consumer_secret']);
     $temporary_credentials = $connection->getRequestToken();
     $this->_ci->session->set_userdata('oauth_token', $temporary_credentials['oauth_token']);
     $this->_ci->session->set_userdata('oauth_token_secret', $temporary_credentials['oauth_token_secret']);
     $redirect_url = $connection->getAuthorizeURL($temporary_credentials);
     return $redirect_url;
 }
开发者ID:andrewkrug,项目名称:repucaution,代码行数:16,代码来源:Twitter.php

示例13: redirectToTwitter

 public function redirectToTwitter()
 {
     $connection = new \TwitterOAuth($this->client_id, $this->client_secret);
     $request_token = $connection->getRequestToken($this->callback);
     $redirect_url = $connection->getAuthorizeURL($request_token, false);
     Session::put("request_oauth_token", $request_token['oauth_token']);
     Session::put("request_oauth_token_secret", $request_token['oauth_token_secret']);
     return Redirect::to($redirect_url);
 }
开发者ID:afolson,项目名称:isfrankfamousyet,代码行数:9,代码来源:TwitterController.php

示例14: signin

 /**
  * Setup and handle the signin via the TwitterOAuth class.
  * User must be logged on, otherwise it shouldn't be allowed to even link this! 
  */
 public function signin()
 {
     if (Member::currentUserID()) {
         $siteconfig = SiteConfig::current_site_config();
         $conn = new TwitterOAuth($siteconfig->ConsumerKey, $siteconfig->ConsumerSecret);
         $temp = $conn->getRequestToken(Director::absoluteBaseURL() . 'TwitterController/callback');
         $redirURL = $conn->getAuthorizeURL($temp);
         $this->redirect($redirURL);
     }
 }
开发者ID:helpfulrobot,项目名称:firesphere-social,代码行数:14,代码来源:TwitterController.php

示例15: authControl

 /**
  * @return str
  */
 public function authControl()
 {
     $config = Config::getInstance();
     Loader::definePathConstants();
     $this->setViewTemplate(THINKUP_WEBAPP_PATH . 'plugins/twitterrealtime/view/twitterrealtime.account.index.tpl');
     $this->view_mgr->addHelp('twitterrealtime', 'userguide/settings/plugins/twitterrealtime');
     $id = DAOFactory::getDAO('InstanceDAO');
     $od = DAOFactory::getDAO('OwnerDAO');
     // get plugin option values if defined...
     $plugin_options = $this->getPluginOptions();
     // get oauth option values from twitter plugin.
     // @TODO -- what is the right way to do this?
     $plugin_option_dao = DAOFactory::GetDAO('PluginOptionDAO');
     $twitter_options = $plugin_option_dao->getOptionsHash('twitter', true);
     $oauth_consumer_key = null;
     if (isset($twitter_options['oauth_consumer_key'])) {
         $oauth_consumer_key = $twitter_options['oauth_consumer_key']->option_value;
     }
     $oauth_consumer_secret = null;
     if (isset($twitter_options['oauth_consumer_secret'])) {
         $oauth_consumer_secret = $twitter_options['oauth_consumer_secret']->option_value;
     }
     // @TODO - get any other option values as necessary
     // $archive_limit = $this->getPluginOption('archive_limit');
     $auth_from_twitter = '';
     if (isset($oauth_consumer_key) && isset($oauth_consumer_secret)) {
         $to = new TwitterOAuth($oauth_consumer_key, $oauth_consumer_secret);
         /* Request tokens from twitter */
         $tok = $to->getRequestToken();
         if (isset($tok['oauth_token'])) {
             $token = $tok['oauth_token'];
             $_SESSION['oauth_request_token_secret'] = $tok['oauth_token_secret'];
             /* Build the authorization URL */
             $oauthorize_link = $to->getAuthorizeURL($token);
             // create indication that auth from twitter plugin is okay
             $auth_from_twitter = "Using the Twitter Consumer key and secret as set in " . "the <a href=\"./?p=twitter\">Twitter plugin</a>.";
         } else {
             //set error message here
             $this->addErrorMessage("Unable to obtain OAuth token. Check your Twitter plugin consumer key and secret configuration.");
             $oauthorize_link = '';
         }
     } else {
         $this->addErrorMessage("Missing required settings! Please configure the Twitter plugin.");
         $oauthorize_link = '';
     }
     $owner_instances = $id->getByOwnerAndNetwork($this->owner, 'twitter');
     $this->addToView('owner_instances', $owner_instances);
     $this->addToView('oauthorize_link', $oauthorize_link);
     $this->addToView('auth_from_twitter', $auth_from_twitter);
     // add plugin options from
     $this->addOptionForm();
     $plugin = new TwitterRealtimePlugin();
     $this->addToView('is_configured', $plugin->isConfigured());
     return $this->generateView();
 }
开发者ID:dgw,项目名称:ThinkUp,代码行数:58,代码来源:class.TwitterRealtimePluginConfigurationController.php


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