2009-08-25 18 views

Odpowiedz

8

Urządzenie verify_credentials API request zwróci informacje o aktualnie zalogowanym użytkowniku.

Ponadto odpowiedź Twittera na żądanie tokenu dostępu OAuth (tj. Ostatnia część procedury logowania OAuth) odpowiada za pomocą nazwy użytkownika i identyfikatora użytkownika Twitter obok zwykłego tokenu i tajnego klucza.

+1

Jak przechwycić tych co? – fixmycode

1

Korzystanie z biblioteki Twitterizer, tutaj jest fragment kodu.

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

long UserID = reqToken.UserId; 

string ScreenName = reqToken.ScreenName; 

Wysłałem przykładowy kod na moim blogu. http://www.fairnet.com/post/2010/09/05/Twitter-authentication-using-OAuth.aspx

+0

Czy otrzymujemy tylko te szczegóły UserID i ScreenName tylko ze Twittera? Również twój blog nie dostaje. Wystąpił błąd, gdy zasób nie został znaleziony. – NCA

2

Oto kod, który używa uwierzytelniania oauth 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 i oAuthUttilityKlasy i zrozumieć, jak to działa Login with twitter using oauth authentication in asp.net and get access token, screen name and userid.

+0

Dobrze. o otrzymujemy tylko te szczegóły UserID i ScreenName tylko ze Twittera. Jak możemy uzyskać inne informacje, takie jak numer telefonu, zdjęcie itp. – NCA

Powiązane problemy