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


PHP UI::readline方法代码示例

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


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

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

示例2: authLastfm

 protected function authLastfm()
 {
     $vars = array();
     $vars['apiKey'] = $this->config['api_key'];
     $vars['secret'] = $this->config['api_secret'];
     $token = new lastfmApiAuth('gettoken', $vars);
     if (!empty($token->error)) {
         throw new RuntimeException("Error fetching Last.fm auth token: " . $token->error['desc']);
     }
     $vars['token'] = $token->token;
     $url = 'http://www.last.fm/api/auth?api_key=' . $vars['apiKey'] . '&token=' . $vars['token'];
     // Automatically send the user to the auth page.
     $ui = new UI();
     $ui->openBrowser($url);
     $ui->readline("Please visit {$url} then press Enter...");
     $auth = new lastfmApiAuth('getsession', $vars);
     if (!empty($auth->error)) {
         throw new RuntimeException("Error fetching Last.fm session key: " . $auth->error['desc'] . ". (Did you authorize the app?)");
     }
     echo "Your session key is {$auth->sessionKey} for user {$auth->username} (written to lastfm-{$auth->username}.txt)\n";
     if (file_put_contents("lastfm-{$auth->username}.txt", $auth->sessionKey)) {
         return;
     }
     throw new RuntimeException("Failed to save session key to lastfm-{$auth->username}.txt");
 }
开发者ID:rabyunghwa,项目名称:sslscrobbler,代码行数:25,代码来源:LastfmPlugin.php


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