public function logout() { $twitterOauth = TwitterOauth::where('user_id', $_SESSION['user_id'])->first(); $twitterOauth->update(['oauth_token' => NULL, 'oauth_token_secret' => NULL, 'screen_name' => NULL, 'oauth_verifier' => false]); unset($_SESSION['twitter']['oauth_token'], $_SESSION['twitter']['oauth_token_secret'], $_SESSION['twitter']['screen_name'], $_SESSION['twitter']['twitterOauth']); return $this->cb->logout(); }
/** * @return string * @throws \Exception */ public function getLoginUrl() { /* Get temporary credentials. */ $request_token = $this->provider->getRequestToken($this->config['oauth_callback']); //if( $this->provider->http_code != 200 ) throw new \Exception('Problem connecting to Twitter'); /* Save temporary credentials to session. */ $_SESSION['oauth_token'] = $request_token['oauth_token']; $_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret']; return $this->provider->getAuthorizeURL($_SESSION['oauth_token']); }
<?php //Twitter Authentication redirect. Establishes new connection with key, secret, and gets request tokens to create twitter authentication connectio session_start(); require 'twitteroauth/twitteroauth.php'; require 'config.php'; $connection = new TwitterOauth(CONSUMER_KEY, CONSUMER_SECRET); $request_token = $connection->getRequestToken(OAUTH_CALLBACK); $_SESSION['oauth_token'] = $token = $request_token['oauth_token']; $_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret']; switch ($connection->http_code) { case 200: $url = $connection->getAuthorizeURL($token); header('Location: ' . $url); break; default: echo "Oops! Something went wrong! Check in the Twitter Docs for this\r\n HTTP CODE" . $connection->http_code; }
<?php require "twitteroauth/autoload.php"; use Abraham\TwitterOAuth\TwitterOAuth; session_start(); include "twitteroauth/src/TwitterOauth.php"; $apikey = "FXtRYedLkkh6iFvBU24VcmbYg"; $apisecret = "CLJGTu8l2rAfF9XlGsGrhSxMUVSUWDcNbd914ReSNx07nmt1Vs"; $accesstoken = "3136064683-dUWF7TQpArgT0tWXh72nD4prEkChRdECz8ZSB5w"; $accesssecret = "vFUAehLAtLDJkyqVMQai6eOM1Y0M3cKSzZQbzJP0Ibyo3"; $connection = new TwitterOauth($apikey, $apisecret, $accesstoken, $accesssecret); //print_r($connection); //$content = $connection->get("account/verify_credentials"); //print_r($content); //$statues = $connection->post("statuses/update", array("status" => "hello world")); $statues = $connection->get("statuses/home_timeline", array("count" => 25, "exclude_replies" => true)); echo json_encode(print_r($statues)); foreach ($statues as $status) { echo $status->text; echo "<br/>"; }
<?php session_start(); require_once 'twitteroauth/twitteroauth.php'; require_once 'config.php'; if (isset($_REQUEST['oauth_token']) && $_SESSION['oauth_token'] !== $_REQUEST['oauth_token']) { $_SESSION['status'] = 'old token'; header('Location: clearsessions.php'); } $connection = new TwitterOauth(CONSUMER_KEY, CONSUMER_SECRET, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']); $access_token = $connection->getAccessToken($_REQUEST['oauth_verifier']); $_SESSION['access_token'] = $access_token; unset($_SESSION['oauth_token']); unset($_SESSION['oauth_token_secret']); if ($connection->http_code == 200) { $_SESSION['status'] = 'verified'; header('Location: index2.php'); } else { header('Location: clearsessions.php'); }