· 6 years ago · Jan 21, 2019, 02:44 PM
1function access_token($tmhOAuth) {
2 $tmhOAuth->config['user_token'] = $_SESSION['oauth']['oauth_token'];
3 $tmhOAuth->config['user_secret'] = $_SESSION['oauth']['oauth_token_secret'];
4
5 //store user token and secret to a session to be accessed on a different page
6 $_SESSION['u_token'] = $tmhOAuth->config['user_token'];
7 $_SESSION['u_secret'] = $tmhOAuth->config['user_secret'];
8
9 $code = $tmhOAuth->request(
10 'POST',
11 $tmhOAuth->url('oauth/access_token', ''),
12 array(
13 'oauth_verifier' => $_REQUEST['oauth_verifier']
14 )
15 );
16
17 if ($code == 200) {
18 $_SESSION['access_token'] = $tmhOAuth->extract_params($tmhOAuth->response['response']);
19 unset($_SESSION['oauth']);
20 header('Location: ' . tmhUtilities::php_self());
21 } else {
22 outputError($tmhOAuth);
23 }
24}
25
26$tmhOAuth = new tmhOAuth(array(
27 'consumer_key' => 'xxx',
28 'consumer_secret' => 'xxx',
29 $_SESSION['u_token'],
30 $_SESSION['u_secret']
31));
32
33$tweet = 'tweet';
34
35$code = $tmhOAuth->request('POST', $tmhOAuth->url('1/statuses/update'), array(
36 'status' => $tweet
37));
38
39echo json_encode($code); //I always get 401 here
40?>
41
42'oauth_token' => $_REQUEST['oauth_token']
43
44$code = $tmhOAuth->request(
45 'POST',
46 $tmhOAuth->url('oauth/access_token', ''),
47 array(
48 'oauth_verifier' => $_REQUEST['oauth_verifier'],
49 'oauth_token' => $_REQUEST['oauth_token']
50 )
51);