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 49 50
| <?php
$client = new GuzzleHttp\Client();
$api_key = "your_api_key"; $api_secret = "your_api_secret";
$response = $client->post('https://api.twitter.com/oauth/request_token', [ 'auth' => [$api_key, $api_secret], 'form_params' => [ 'x_auth_mode' => 'client_auth', 'x_auth_username' => 'your_username', 'x_auth_password' => 'your_password', ], ]);
parse_str($response->getBody()->getContents(), $request_token);
$authorize_url = "https://api.twitter.com/oauth/authorize?oauth_token={$request_token['oauth_token']}";
echo "Please visit the following URL to authorize your account:\n"; echo "$authorize_url\n";
echo "Enter the PIN code: "; $pin_code = trim(fgets(STDIN));
$response = $client->post('https://api.twitter.com/oauth/access_token', [ 'auth' => [$api_key, $api_secret], 'form_params' => [ 'oauth_verifier' => $pin_code, 'oauth_token' => $request_token['oauth_token'], ], ]);
parse_str($response->getBody()->getContents(), $access_token);
echo "Your access token:\n"; echo "oauth_token: {$access_token['oauth_token']}\n"; echo "oauth_token_secret: {$access_token['oauth_token_secret']}\n";
|