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


PHP TwitterOAuth::getAuthorizeUrl方法代码示例

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


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

示例1: twitterLogin

 function twitterLogin()
 {
     $request = $_REQUEST;
     $site = $this->siteUrl();
     $callBackUrl = $this->callBackUrl();
     $response = new stdClass();
     $exploder = explode('_', $_GET['apsl_login_id']);
     $action = $exploder[1];
     @session_start();
     $options = get_option(APSL_SETTINGS);
     if ($action == 'login') {
         // Get identity from user and redirect browser to OpenID Server
         if (!isset($request['oauth_token']) || $request['oauth_token'] == '') {
             $twitterObj = new TwitterOAuth($options['apsl_twitter_settings']['apsl_twitter_api_key'], $options['apsl_twitter_settings']['apsl_twitter_api_secret']);
             $encoded_url = isset($_GET['redirect_to']) ? $_GET['redirect_to'] : '';
             if (isset($encoded_url) && $encoded_url != '') {
                 $callback = $callBackUrl . 'apsl_login_id' . '=twitter_check&redirect_to=' . $encoded_url;
             } else {
                 $callback = $callBackUrl . 'apsl_login_id' . '=twitter_check';
             }
             $request_token = $twitterObj->getRequestToken($callback);
             $_SESSION['oauth_twitter'] = array();
             /* Save temporary credentials to session. */
             $_SESSION['oauth_twitter']['oauth_token'] = $token = $request_token['oauth_token'];
             $_SESSION['oauth_twitter']['oauth_token_secret'] = $request_token['oauth_token_secret'];
             /* If last connection failed don't display authorization link. */
             switch ($twitterObj->http_code) {
                 case 200:
                     try {
                         $url = $twitterObj->getAuthorizeUrl($token);
                         $this->redirect($url);
                     } catch (Exception $e) {
                         $response->status = 'ERROR';
                         $response->error_code = 2;
                         $response->error_message = 'Could not get AuthorizeUrl.';
                     }
                     break;
                 default:
                     $response->status = 'ERROR';
                     $response->error_code = 2;
                     $response->error_message = 'Could not connect to Twitter. Refresh the page or try again later.';
                     break;
             }
         } else {
             $response->status = 'ERROR';
             $response->error_code = 2;
             $response->error_message = 'INVALID AUTHORIZATION';
         }
     } else {
         if (isset($request['oauth_token']) && isset($request['oauth_verifier'])) {
             /* Create TwitteroAuth object with app key/secret and token key/secret from default phase */
             $twitterObj = new TwitterOAuth($options['apsl_twitter_settings']['apsl_twitter_api_key'], $options['apsl_twitter_settings']['apsl_twitter_api_secret'], $_SESSION['oauth_twitter']['oauth_token'], $_SESSION['oauth_twitter']['oauth_token_secret']);
             /* Remove no longer needed request tokens */
             unset($_SESSION['oauth_twitter']);
             try {
                 $access_token = $twitterObj->getAccessToken($request['oauth_verifier']);
                 /* If HTTP response is 200 continue otherwise send to connect page to retry */
                 if (200 == $twitterObj->http_code) {
                     $user_profile = $twitterObj->get('users/show', array('screen_name' => $access_token['screen_name'], 'include_entities' => true));
                     /* Request access twitterObj from twitter */
                     $response->status = 'SUCCESS';
                     $response->deuid = $user_profile->id;
                     $response->deutype = 'twitter';
                     $response->name = explode(' ', $user_profile->name, 2);
                     $response->first_name = $response->name[0];
                     $response->last_name = isset($response->name[1]) ? $response->name[1] : '';
                     $response->deuimage = $user_profile->profile_image_url_https;
                     $response->email = $user_profile->screen_name . '@twitter.com';
                     $response->username = $user_profile->screen_name . '@twitter.com';
                     $response->url = $user_profile->url;
                     $response->about = $user_profile->description;
                     $response->gender = $user_profile->gender;
                     $response->location = $user_profile->location;
                     $response->error_message = '';
                 } else {
                     $response->status = 'ERROR';
                     $response->error_code = 2;
                     $response->error_message = 'Could not connect to Twitter. Refresh the page or try again later.';
                 }
             } catch (Exception $e) {
                 $response->status = 'ERROR';
                 $response->error_code = 2;
                 $response->error_message = 'Could not get AccessToken.';
             }
         } else {
             // User Canceled your Request
             $response->status = 'ERROR';
             $response->error_code = 1;
             $response->error_message = "USER CANCELED REQUEST";
         }
     }
     return $response;
 }
开发者ID:Vivekbhusal,项目名称:EnergySmartResident,代码行数:93,代码来源:login_check.php


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