Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Twitter User Name after oauth Authentication

Using oAuth i can able to sucessfully login and forward it back to my asp.net application.

how can i get the username of the authenticated person. At this point i just have an authenticated oAuth.

like image 374
vamsivanka Avatar asked Aug 25 '09 20:08

vamsivanka


3 Answers

The verify_credentials API request will return information about the currently logged in user.

Also, Twitter's response to an OAuth access token request (i.e. the last part of the OAuth login procedure) responds with the user's screen name and Twitter user ID alongside the usual oauth token and secret.

like image 144
David Carrington Avatar answered Oct 27 '22 14:10

David Carrington


Here is the code that use oauth authentication 1.0.

Login with twitter using oauth authentication in asp.net and get access token, screen name and userid.

    OAuthHelper oauthhelper = new OAuthHelper();
    string requestToken = oauthhelper.GetRequestToken();

     if (string.IsNullOrEmpty(oauthhelper.oauth_error))
         Response.Redirect(oauthhelper.GetAuthorizeUrl(requestToken));
     else
          Response.Write(oauthhelper.oauth_error);

Return Url.

    if (Request.QueryString["oauth_token"] != null && Request.QueryString["oauth_verifier"]!=null)
    {
        string oauth_token = Request.QueryString["oauth_token"];
        string oauth_verifier = Request.QueryString["oauth_verifier"];

        OAuthHelper oauthhelper = new OAuthHelper();
        oauthhelper.GetUserTwAccessToken(oauth_token, oauth_verifier);

        if (string.IsNullOrEmpty(oauthhelper.oauth_error))
        {
            Session["twtoken"] = oauthhelper.oauth_access_token;
            Session["twsecret"] = oauthhelper.oauth_access_token_secret;
            Session["twuserid"] = oauthhelper.user_id;
            Session["twname"] = oauthhelper.screen_name;


            Response.Write("<b>AccessToken=</b>" + oauthhelper.oauth_access_token);
            Response.Write("<br /><b>Access Secret=</b>" + oauthhelper.oauth_access_token_secret);
            Response.Write("<br /><b>Screen Name=</b>" + oauthhelper.screen_name);
            Response.Write("<br /><b>Twitter User ID=</b>" + oauthhelper.user_id);
        }
        else
            Response.Write(oauthhelper.oauth_error);
    }

Get oAuthHelper and oAuthUttility Classes and understand how it works Login with twitter using oauth authentication in asp.net and get access token, screen name and userid.

like image 29
Rohit Avatar answered Oct 27 '22 14:10

Rohit


Using Twitterizer library, here is a code snippet.

OAuthTokenResponse reqToken = OAuthUtility.GetAccessToken(ConsumerKey, ConsumerSecret, requestToken);

long UserID = reqToken.UserId;

string ScreenName = reqToken.ScreenName;

I've posted a sample code on my blog. http://www.fairnet.com/post/2010/09/05/Twitter-authentication-using-OAuth.aspx

like image 39
Farooq Kaiser Avatar answered Oct 27 '22 14:10

Farooq Kaiser