You are here

function _twitter_signin_add_account in Twitter 7.6

Same name and namespace in other branches
  1. 6.5 twitter_signin/twitter_signin.module \_twitter_signin_add_account()
  2. 7.3 twitter_signin/twitter_signin.module \_twitter_signin_add_account()
  3. 7.4 twitter_signin/twitter_signin.module \_twitter_signin_add_account()
  4. 7.5 twitter_signin/twitter_signin.module \_twitter_signin_add_account()

Relates a user account with a Twitter account.

Parameters

$account: The Drupal user account.

2 calls to _twitter_signin_add_account()
twitter_signin_user_insert in twitter_signin/twitter_signin.module
Implements hook_user_insert().
twitter_signin_user_login in twitter_signin/twitter_signin.module
Implements hook_user_login().

File

twitter_signin/twitter_signin.module, line 294
Hook implementations for Twitter Signin module.

Code

function _twitter_signin_add_account($edit, $account) {
  if (isset($_SESSION['twitter']['values'])) {
    module_load_include('inc', 'twitter');
    $key = variable_get('twitter_consumer_key', '');
    $secret = variable_get('twitter_consumer_secret', '');
    $response = $_SESSION['twitter']['values'];
    $twitter = new Twitter($key, $secret, $response['oauth_token'], $response['oauth_token_secret']);
    try {
      $twitter_account = $twitter
        ->users_show($response['screen_name']);
    } catch (TwitterException $e) {
      drupal_set_message(t('Request failed: @message.', array(
        '@message' => $e
          ->getMessage(),
      )), 'error');
      return;
    }
    $twitter_account
      ->set_auth($response);
    $twitter_account->uid = $account->uid;
    twitter_account_save($twitter_account);
    unset($_SESSION['twitter']);
    drupal_set_message(t('You have related a Twitter account with your user. Next time you can sign in with Twitter.'));
  }
}