本文整理汇总了PHP中TwitterOAuth::oauth方法的典型用法代码示例。如果您正苦于以下问题:PHP TwitterOAuth::oauth方法的具体用法?PHP TwitterOAuth::oauth怎么用?PHP TwitterOAuth::oauth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TwitterOAuth
的用法示例。
在下文中一共展示了TwitterOAuth::oauth方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: CheckTWLogin
public function CheckTWLogin()
{
$user = false;
require_once ROOTPATH . "data/third_party/twitteroauth/src/TwitterOAuth.php";
$ckey = 'K9SC8vPbbj1V86cUcSl93m2kA';
$csecret = 'RHfA9S74g9yHPydM4DURpNZyvVm7RU0s7Ci2O070FFG5oAyBC7';
$access_token = '279588839-8TjR5fwRhuyNySAxUZb6NZIo9w1ymTL1EJJwJE81';
$access_token_secret = '3LOuzmGKm6HulMjWEfTYLjM20FokhJQeYD8BPJQhfcfYH';
if ($this->input->get('oauth_token') && $this->input->get('oauth_verifier')) {
$request_token = array();
$request_token['oauth_token'] = $this->session->userdata('oauth_token');
$request_token['oauth_token_secret'] = $this->session->userdata('oauth_token_secret');
if (!$request_token['oauth_token'] || !$request_token['oauth_token_secret'] || $request_token['oauth_token'] !== $this->input->get('oauth_token')) {
return false;
}
$connection = new TwitterOAuth($ckey, $csecret, $request_token['oauth_token'], $request_token['oauth_token_secret']);
$access_token = false;
try {
$access_token = $connection->oauth("oauth/access_token", array("oauth_verifier" => $this->input->get('oauth_verifier')));
} catch (Exception $e) {
}
if (!$access_token) {
return false;
}
$connection = new TwitterOAuth($ckey, $csecret, $access_token['oauth_token'], $access_token['oauth_token_secret']);
$user = $connection->get("account/verify_credentials", array("include_email" => 'true'));
return $user;
}
$connection = new TwitterOAuth($ckey, $csecret, $access_token, $access_token_secret);
$request_token = $connection->oauth('oauth/request_token', array('oauth_callback' => base_url() . 'informados/user/twitter'));
$url = $connection->url('oauth/authorize', array('oauth_token' => $request_token['oauth_token']));
$this->session->set_userdata('oauth_token', $request_token['oauth_token']);
$this->session->set_userdata('oauth_token_secret', $request_token['oauth_token_secret']);
redirect($url);
return false;
}
示例2: die
<?php
session_start();
require_once 'common.php';
// トークン妥当性チェック
if (isset($_REQUEST['oauth_token']) && $_SESSION['oauth_token'] !== $_REQUEST['oauth_token']) {
die('Error!');
}
// OAuthトークンを加えてTwitterOAuthをインスタンス化
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
// access_tokenを取得
$access_token = $connection->oauth("oauth/access_token", array("oauth_verifier" => $_REQUEST['oauth_verifier']));
// 取得したアクセストークンとシークレットでTwitterOAuthをインスタンス化
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);
// ユーザー情報をGET
$user = $connection->get("account/verify_credentials");
// ユーザーデータを追加保存
$data = unserialize(file_get_contents('./users.dat'));
if (!is_array($data)) {
$data = array();
}
$data[(string) $user->id] = array('access_token' => $access_token['oauth_token'], 'oauth_token_secret' => $access_token['oauth_token_secret']);
file_put_contents('./users.dat', serialize($data));
// リダイレクト
header('location: /complete.php');
示例3: TwitterOAuth
<?php
session_start();
require_once 'common.php';
// TwitterOAuth をインスタンス化
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
// コールバックURLをここでセット
$token = $connection->oauth('oauth/request_token', array('oauth_callback' => OAUTH_CALLBACK));
// callback.phpで使うのでセッションに保存
$_SESSION = array('oauth_token' => $token['oauth_token'], 'oauth_token_secret' => $token['oauth_token_secret']);
// Twitter.comの認証画面のURLを取得
$url = $connection->url('oauth/authenticate', array('oauth_token' => $token['oauth_token']));
// 認証画面へリダイレクト
header('location: ' . $url);
示例4: TwitterAccess
public function TwitterAccess()
{
require_once ROOTPATH . "data/third_party/twitteroauth/src/TwitterOAuth.php";
if ($this->input->get('oauth_token') && $this->input->get('oauth_verifier')) {
$request_token = array();
$request_token['oauth_token'] = $this->session->userdata('oauth_token');
$request_token['oauth_token_secret'] = $this->session->userdata('oauth_token_secret');
if (!$request_token['oauth_token'] || !$request_token['oauth_token_secret'] || $request_token['oauth_token'] !== $this->input->get('oauth_token')) {
$this->result = $this->type . "oauth_token inválido";
return false;
}
$connection = new TwitterOAuth($this->twitter_config['ckey'], $this->twitter_config['csecret'], $request_token['oauth_token'], $request_token['oauth_token_secret']);
$access_token = false;
try {
$access_token = $connection->oauth("oauth/access_token", array("oauth_verifier" => $this->input->get('oauth_verifier')));
} catch (Exception $e) {
}
if (!$access_token) {
$this->result = $this->type . "access_token inválido";
return false;
}
$this->TwitterData($access_token);
return true;
}
$connection = new TwitterOAuth($this->twitter_config['ckey'], $this->twitter_config['csecret'], $this->twitter_config['access_token'], $this->twitter_config['access_token_secret']);
$request_token = $connection->oauth('oauth/request_token', array('oauth_callback' => base_url() . 'apps/social/add/twitter'));
$url = $connection->url('oauth/authorize', array('oauth_token' => $request_token['oauth_token']));
$this->session->set_userdata('oauth_token', $request_token['oauth_token']);
$this->session->set_userdata('oauth_token_secret', $request_token['oauth_token_secret']);
redirect($url);
return false;
}