You are here

function twitter_account_oauth_validate in Twitter 7.3

Same name and namespace in other branches
  1. 6.3 twitter.pages.inc \twitter_account_oauth_validate()

If OAuth is enabled, intercept submission of 'Add Account' form on user/%/edit/twitter page and redirect to Twitter for auth.

1 string reference to 'twitter_account_oauth_validate'
twitter_account_form in ./twitter.pages.inc
Form to add a Twitter account

File

./twitter.pages.inc, line 358
Page callbacks for Twitter module.

Code

function twitter_account_oauth_validate($form, &$form_state) {
  module_load_include('lib.php', 'oauth_common');
  module_load_include('lib.php', 'twitter');
  $key = variable_get('twitter_consumer_key', '');
  $secret = variable_get('twitter_consumer_secret', '');
  if ($key == '' || $secret == '') {
    form_set_error('', t('Please configure your Twitter consumer key and secret.'));
  }
  $twitter = new TwitterOAuth($key, $secret);
  $token = $twitter
    ->get_request_token();
  $_SESSION['twitter_oauth']['account'] = user_load($form['uid']['#value']);
  $_SESSION['twitter_oauth']['token'] = $token;
  $_SESSION['twitter_oauth']['destination'] = $_GET['q'];
  drupal_goto($twitter
    ->get_authorize_url($token));
}