コード例 #1
0
<?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
0
ファイル: callback.php プロジェクト: ajireza/api-twitter
<?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
0
ファイル: index.php プロジェクト: ajireza/api-twitter
<?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
0
ファイル: login.php プロジェクト: ajireza/api-twitter
<?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;
}