Skip to content

Commit dccb143

Browse files
committed
tiktok api access tokens and users info
1 parent 46eae7a commit dccb143

9 files changed

Lines changed: 483 additions & 0 deletions

File tree

tiktokapi/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#-------------------------
2+
# Composer
3+
#-------------------------
4+
vendor/
5+
composer.lock

tiktokapi/assets/app_icon.png

126 KB
Loading

tiktokapi/assets/favicon.ico

6.62 KB
Binary file not shown.

tiktokapi/assets/tiktok_logo.png

4.17 KB
Loading

tiktokapi/composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"require": {
3+
"jstolpe/tiktok-api-php-sdk": "^1.0"
4+
}
5+
}

tiktokapi/defines.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
define( 'CLIENT_KEY', '<CLIENT_KEY>' );
3+
define( 'CLIENT_SECRET', '<CLIENT_SECRET>' );
4+
define( 'REDIRECT_URI', '<REDIRECT_URI>' );
5+
define( 'USER_ACCESS_TOKEN', '<USER_ACCESS_TOKEN>' );
6+
define( 'REFRESH_TOKEN', '<REFRESH_TOKEN>' );
7+
?>

tiktokapi/index.php

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<?php
2+
require_once 'defines.php';
3+
require_once 'vendor/autoload.php'; // composer
4+
//require_once 'tiktok-api-php-sdk/src/TikTok/autoload.php'; // not composer
5+
6+
use TikTok\Authentication\Authentication;
7+
8+
$authentication = new Authentication( array( // instantiate authentication
9+
'client_key' => CLIENT_KEY, // client key from your app
10+
'client_secret' => CLIENT_SECRET // client secret from your app
11+
) );
12+
13+
// uri TikTok will send the user to after they login that must match what you have in your app dashboard
14+
$redirectUri = REDIRECT_URI;
15+
16+
$scopes = array( // a list of approved scopes by tiktok for your app
17+
'user.info.basic',
18+
'user.info.profile',
19+
'user.info.stats'
20+
);
21+
22+
// get TikTok login url
23+
$authenticationUrl = $authentication->getAuthenticationUrl( $redirectUri, $scopes );
24+
?>
25+
<html>
26+
<head>
27+
<title>
28+
Bubbles | Rubber Duck Videos
29+
</title>
30+
31+
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
32+
33+
<link rel="shortcut icon" href="assets/favicon.ico" />
34+
35+
<style>
36+
body {
37+
font-family: 'Courier New';
38+
background: #f0f2f5;
39+
}
40+
41+
a {
42+
text-decoration: none;
43+
}
44+
45+
.login-container {
46+
max-width: 400px;
47+
background: #fff;
48+
padding: 20px;
49+
border-radius: 5px;
50+
box-shadow: 0 2px 4px rgba( 0, 0, 0, .1 ), 0 8px 16px rgba( 0, 0, 0, .1 );
51+
font-weight: bold;
52+
font-size: 30px;
53+
text-align: center;
54+
left: 50%;
55+
top: 50%;
56+
transform: translate( -50%, -50% );
57+
position: fixed;
58+
}
59+
60+
.app-icon {
61+
height: 50px;
62+
}
63+
64+
.tiktok-button {
65+
margin-top: 20px;
66+
padding: 20px;
67+
background: #000;
68+
color: #fff;
69+
border-radius: 5px;
70+
font-size: 18px;
71+
cursor: pointer;
72+
}
73+
74+
.tiktok-button:hover {
75+
background: #181818;
76+
}
77+
78+
.tiktok-button:active {
79+
box-shadow: inset 0 0 20px #ffffff;
80+
}
81+
82+
.tiktok-button img {
83+
height: 15px;
84+
}
85+
86+
.sub-text {
87+
text-align: center;
88+
font-size: 12px;
89+
font-weight: normal;
90+
margin-top: 20px;
91+
margin-bottom: 20px
92+
}
93+
94+
@media only screen and ( max-width: 1000px ) { /* mobile: do things when size is 1200px or less */
95+
.login-container {
96+
transform: none;
97+
position: unset;
98+
}
99+
}
100+
</style>
101+
</head>
102+
<body>
103+
<div class="login-container">
104+
<img class="app-icon" src="assets/app_icon.png" />
105+
<div>
106+
Bubbles Log In
107+
</div>
108+
<div class="sub-text">
109+
This is a site aimed at helping you learn how to easily integrate and use the TikTok API. Check out the <a href="https://www.youtube.com/watch?v=sdA4eCq21y8&list=PL0glhsZ01I-BWvKCRnZtkG4bBoOB3LivT" target="_blank">YouTube TikTok API PHP SDK Playlist</a> to learn more! You can also find the code and wiki on <a href="https://github.com/jstolpe/tiktok-api-php-sdk" target="_blank">Github</a>.
110+
</div>
111+
<a href="<?php echo $authenticationUrl; ?>">
112+
<div class="tiktok-button">
113+
<img src="assets/tiktok_logo.png" /> Continue with TikTok
114+
</div>
115+
</a>
116+
</div>
117+
</body>
118+
</html>

tiktokapi/login.php

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<?php
2+
require_once 'defines.php';
3+
require_once 'vendor/autoload.php'; // composer
4+
//require_once 'tiktok-api-php-sdk/src/TikTok/autoload.php'; // not composer
5+
6+
use TikTok\Authentication\Authentication;
7+
8+
// get authorization code
9+
$authorizationCode = isset( $_GET['code'] ) ? $_GET['code'] : '';
10+
11+
$authentication = new Authentication( array( // instantiate authentication
12+
'client_key' => CLIENT_KEY,
13+
'client_secret' => CLIENT_SECRET
14+
) );
15+
16+
if ( $authorizationCode ) { // try and get access token from code
17+
// get access token from code
18+
$userToken = $authentication->getAccessTokenFromCode( $authorizationCode, REDIRECT_URI );
19+
}
20+
?>
21+
<html>
22+
<head>
23+
<title>
24+
Bubbles | Rubber Duck Videos
25+
</title>
26+
27+
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
28+
29+
<link rel="shortcut icon" href="assets/favicon.ico" />
30+
31+
<style>
32+
body {
33+
font-family: 'Courier New';
34+
background: #f0f2f5;
35+
}
36+
37+
a {
38+
text-decoration: none;
39+
}
40+
41+
input {
42+
width: 100%;
43+
padding: 10px;
44+
box-sizing: border-box;
45+
border: 1px solid #dedede;
46+
border-radius: 5px;
47+
}
48+
49+
textarea {
50+
width: 100%;
51+
padding: 10px;
52+
box-sizing: border-box;
53+
border: 1px solid #dedede;
54+
border-radius: 5px;
55+
height: 300px;
56+
}
57+
58+
.login-container {
59+
max-width: 400px;
60+
background: #fff;
61+
padding: 20px;
62+
border-radius: 5px;
63+
box-shadow: 0 2px 4px rgba( 0, 0, 0, .1 ), 0 8px 16px rgba( 0, 0, 0, .1 );
64+
font-weight: bold;
65+
font-size: 30px;
66+
text-align: center;
67+
margin: 0 auto;
68+
margin-top: 10px;
69+
}
70+
71+
.app-icon {
72+
height: 50px;
73+
}
74+
75+
.sub-text {
76+
text-align: center;
77+
font-size: 12px;
78+
font-weight: normal;
79+
margin-top: 20px;
80+
margin-bottom: 20px
81+
}
82+
83+
@media only screen and ( max-width: 1000px ) { /* mobile: do things when size is 1200px or less */
84+
.login-container {
85+
transform: none;
86+
position: unset;
87+
}
88+
}
89+
</style>
90+
</head>
91+
<body>
92+
<div class="login-container">
93+
<img class="app-icon" src="assets/app_icon.png" />
94+
<div>
95+
Bubbles Log In
96+
</div>
97+
<div class="sub-text">
98+
This is a site aimed at helping you learn how to easily integrate and use the TikTok API. Check out the <a href="https://www.youtube.com/watch?v=sdA4eCq21y8&list=PL0glhsZ01I-BWvKCRnZtkG4bBoOB3LivT" target="_blank">YouTube TikTok API PHP SDK Playlist</a> to learn more! You can also find the code and wiki on <a href="https://github.com/jstolpe/tiktok-api-php-sdk" target="_blank">Github</a>.
99+
</div>
100+
<div>
101+
Code From TikTok
102+
</div>
103+
<div>
104+
<input type="text" value="<?php echo isset( $_GET['code'] ) ? $_GET['code'] : ''; ?>" placeholder="code from TikTok to exchange for access token" />
105+
</div>
106+
<?php if ( $authorizationCode ) : ?>
107+
<div class="sub-text">
108+
Exchangin code for access token...
109+
</div>
110+
<div>
111+
User Access Token Response
112+
</div>
113+
<div class="sub-text">
114+
<?php echo !empty( $userToken['error'] ) ? $userToken['error_description'] : 'Access Token Found.'; ?>
115+
</div>
116+
<?php endif; ?>
117+
</div>
118+
</body>
119+
</html>

0 commit comments

Comments
 (0)