This repository has been archived by the owner on May 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
callback.php
48 lines (36 loc) · 1.8 KB
/
callback.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
session_start();
require 'twitteroauth/autoload.php';
require 'config.php';
use Abraham\TwitterOAuth\TwitterOAuth;
$callback = (isset($_GET['url'])?$_GET['url']:'my-map.php');
if(isset($_SESSION['access_token'])) {
header("Location: {$callback}");
} else if (isset($_GET['denied'])) {
header("Location: ".isset($_GET['url'])?$callback:'/');
}
else {
$request_token = [];
$request_token['oauth_token'] = $_SESSION['oauth_token'];
$request_token['oauth_token_secret'] = $_SESSION['oauth_token_secret'];
if (isset($_REQUEST['oauth_token']) && $request_token['oauth_token'] !== $_REQUEST['oauth_token']) {
echo "<script>alert('오류 발생!\n다시 진행해주세요!');</script>";
}
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $request_token['oauth_token'], $request_token['oauth_token_secret']);
$access_token = $connection->oauth("oauth/access_token", ["oauth_verifier" => $_REQUEST['oauth_verifier']]);
$_SESSION['access_token'] = $access_token;
// MySQL 데이터베이스 연결
$mysqli = new mysqli('localhost', DB_ID, DB_PW, 'gabolga');
// 연결 오류 발생 시 스크립트 종료
if ($mysqli->connect_errno) {
die('Connect Error: '.$mysqli->connect_error);
}
// 쿼리문 전송
// user_id, screen_name, oauth_token, oauth_token_secret
$query = "INSERT INTO users (user_id, screen_name, oauth_token, oauth_token_secret) VALUES ({$access_token['user_id']}, '{$access_token['screen_name']}', '{$access_token['oauth_token']}', '{$access_token['oauth_token_secret']}') ON DUPLICATE KEY UPDATE screen_name='{$access_token['screen_name']}', oauth_token='{$access_token['oauth_token']}', oauth_token_secret='{$access_token['oauth_token_secret']}' ";
$mysqli->query($query);
// 접속 종료
$mysqli->close();
header("Location: {$callback}");
}
?>