Last active
March 18, 2021 10:49
-
-
Save tkgstrator/827e4fca6c6ec4198c2d6a65877a86ac to your computer and use it in GitHub Desktop.
Twitter OAuth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require "vendor/autoload.php"; | |
use Abraham\TwitterOAuth\TwitterOAuth; | |
session_start(); | |
$CONSUMER_KEY = ""; | |
$CONSUMER_KEY_SECRET = ""; | |
switch (true) { | |
case ($_SERVER["HTTP_HOST"] === "localhost:8080"): | |
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__); | |
$dotenv->load(); | |
$CONSUMER_KEY = $_ENV["CONSUMER_KEY"]; | |
$CONSUMER_KEY_SECRET = $_ENV["CONSUMER_KEY_SECRET"]; | |
break; | |
default: | |
$CONSUMER_KEY = getenv("CONSUMER_KEY"); | |
$CONSUMER_KEY_SECRET = getenv("CONSUMER_KEY_SECRET"); | |
break; | |
} | |
$request_token = []; | |
$request_token['oauth_token'] = $_SESSION['oauth_token']; | |
$request_token['oauth_token_secret'] = $_SESSION['oauth_token_secret']; | |
$connection = new TwitterOAuth($CONSUMER_KEY, $CONSUMER_KEY_SECRET, $request_token['oauth_token'], $request_token['oauth_token_secret']); | |
$access_token = $connection->oauth("oauth/access_token", ["oauth_verifier" => $_REQUEST['oauth_verifier']]); | |
$url = "ikastagram://" . http_build_query($access_token); | |
header("Location: " . $url); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require "vendor/autoload.php"; | |
use Abraham\TwitterOAuth\TwitterOAuth; | |
session_start(); | |
$CONSUMER_KEY = ""; | |
$CONSUMER_KEY_SECRET = ""; | |
switch (true) { | |
case ($_SERVER["HTTP_HOST"] === "localhost:8080"): | |
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__); | |
$dotenv->load(); | |
$CONSUMER_KEY = $_ENV["CONSUMER_KEY"]; | |
$CONSUMER_KEY_SECRET = $_ENV["CONSUMER_KEY_SECRET"]; | |
define("CALLBACK_URL", "http://localhost:8080/callback.php"); | |
break; | |
default: | |
$CONSUMER_KEY = getenv("CONSUMER_KEY"); | |
$CONSUMER_KEY_SECRET = getenv("CONSUMER_KEY_SECRET"); | |
define("CALLBACK_URL", "https://ikastagram.herokuapp.com/callback.php"); | |
break; | |
} | |
$connection = new TwitterOAuth($CONSUMER_KEY, $CONSUMER_KEY_SECRET); | |
$request = $connection->oauth("oauth/request_token", array("oauth_callback" => CALLBACK_URL)); | |
$_SESSION["oauth_token"] = $request["oauth_token"]; | |
$_SESSION["oauth_token_secret"] = $request["oauth_token_secret"]; | |
$url = $connection->url("oauth/authorize", array("oauth_token" => $request["oauth_token"])); | |
header("Location: " . $url); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment