- $connection = new TwitterOAuth($ckey, $csecret, $_POST['twitter-token'], $_POST['twitter-token2']);
- $token = $connection->getAccessToken($_POST['twitter-pin']);
- // ok, now that we have the Access Token, save them in the user config
- PConfig::set(local_user(), 'twitter', 'oauthtoken', $token['oauth_token']);
- PConfig::set(local_user(), 'twitter', 'oauthsecret', $token['oauth_token_secret']);
- PConfig::set(local_user(), 'twitter', 'post', 1);
+ try {
+ if (empty($_POST['twitter-pin'])) {
+ throw new Exception(L10n::t('You submitted an empty PIN, please Sign In with Twitter again to get a new one.'));
+ }
+
+ $connection = new TwitterOAuth($ckey, $csecret, $_POST['twitter-token'], $_POST['twitter-token2']);
+ $token = $connection->oauth("oauth/access_token", ["oauth_verifier" => $_POST['twitter-pin']]);
+ // ok, now that we have the Access Token, save them in the user config
+ PConfig::set(local_user(), 'twitter', 'oauthtoken', $token['oauth_token']);
+ PConfig::set(local_user(), 'twitter', 'oauthsecret', $token['oauth_token_secret']);
+ PConfig::set(local_user(), 'twitter', 'post', 1);
+ } catch(Exception $e) {
+ info($e->getMessage());
+ }