本文整理汇总了PHP中TwitterOAuth::redirect方法的典型用法代码示例。如果您正苦于以下问题:PHP TwitterOAuth::redirect方法的具体用法?PHP TwitterOAuth::redirect怎么用?PHP TwitterOAuth::redirect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TwitterOAuth
的用法示例。
在下文中一共展示了TwitterOAuth::redirect方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: TwitterOAuth
<?php
@session_start();
require_once 'src/twitteroauth.php';
$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
if (!$twitter->isLogged()) {
$twitter->redirect('/');
}
// get data
$data = array();
$search = false;
if (isset($_POST['q']) || isset($_GET['q'])) {
$search = true;
$keyword = isset($_POST['q']) ? $_POST['q'] : $_GET['q'];
$keyword = trim(strip_tags($keyword));
$params = array();
if (count($_POST)) {
$params = array('q' => $keyword, 'count' => 20, 'include_entities' => 1);
} else {
if (count($_GET)) {
$params = $_GET;
}
}
if ($keyword) {
$data = $twitter->get('search/tweets', $params);
$data = $twitter->toArray($data);
}
}
if ($search) {
// echo '<pre>';
// print_r($data);
示例2: TwitterOAuth
<?php
@session_start();
require_once 'src/twitteroauth.php';
$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
/* If the oauth_token is old redirect to the start page. */
if (isset($_REQUEST['oauth_token']) && !$twitter->validRequestToken($_REQUEST['oauth_token'])) {
$twitter->redirect('/logout.php');
}
/* Request main access tokens from twitter */
$access_token = $twitter->refreshAccessToken($_REQUEST['oauth_verifier']);
/* Save the access tokens. Normally these would be saved in a database for future use. */
$twitter->saveAccessToken($access_token);
// redirect to start page
$twitter->redirect('/');
示例3: TwitterOAuth
<?php
@session_start();
require_once 'src/twitteroauth.php';
$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
if ($twitter->isLogged()) {
$twitter->redirect('/profile.php');
}
?>
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Twitter API</title>
<link rel="stylesheet" href="/css/reset.css" type="text/css" />
<link rel="stylesheet" href="/css/bootstrap.css" type="text/css" />
<link rel="stylesheet" href="/css/style.css" type="text/css" />
<script src="/js/jquery.js"></script>
<script src="/js/bootstrap.js"></script>
</head>
<body>
<div id="main" class="container">
<div class="content">
示例4: TwitterOAuth
<?php
@session_start();
require_once 'src/twitteroauth.php';
$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
/* Get temporary credentials. */
$request_token = $twitter->getRequestToken(OAUTH_CALLBACK);
/* Save temporary credentials to session. */
$twitter->saveOAuthToken($request_token);
/* Get token for auth url */
$token = $request_token['oauth_token'];
// if connection code ok - redirect to auth url
if ($twitter->http_code == 200) {
$twitter->redirect($twitter->getAuthorizeURL($token));
} else {
echo 'Could not connect to Twitter. Refresh the page or try again later.';
exit;
}