2016-10-04 4 views
0

私はasp.netでWebアプリケーションを持っています。私はユーザー情報を取得するtwiiterとのログインを使用したい。私は認証後、私は私のローカルホストアプリケーションにリダイレクトされていますその後、Twitterアプリにリダイレクト取得しています記事twitterでログインしてユーザープロファイルを取得するasp.net

http://www.aspsnippets.com/Articles/Login-with-Twitter-in-ASPNet-using-Twitter-Button.aspx

の下で言及したすべての指示に従っています。その後、私はチェックユーザーが許可されているが、方法でユーザーの詳細を取得しようとするとFetchProfile()エラーが発生しています。

私のコードは以下の通りです:ボタンを

まずバックTwitterから認証した後、その後

protected void LoginTwitter(object sender, EventArgs e) 
{ 

    if (!TwitterConnect.IsAuthorized) 
    { 
     TwitterConnect twitter = new TwitterConnect(); 
     twitter.Authorize(Request.Url.AbsoluteUri.Split('?')[0]); 
    } 

} 

をクリックします。アプリケーション のページのロードに私はチェックのURLを持っているその

http://localhost:63977/Account/Login?oauth_token=K0mECAAAAAAAxRXEAAABV44xPgc&oauth_verifier=qYLFiOlFPx4gxEu6V4AmTJG2JNjJ3nV2 

、コード

protected void Page_Load(object sender, EventArgs e) 
{ 
    TwitterConnect.API_Key = HelperClasses.TwitterApiKey; 
    TwitterConnect.API_Secret = HelperClasses.TwitterApiSecret; 

    if (Request.QueryString["oauth_token"] != null) 
    { 
     //twiiter 
     if (TwitterConnect.IsAuthorized) 
     { 
      TwitterConnect twitter = new TwitterConnect(); 
      //LoggedIn User Twitter Profile Details 
      DataTable twitterUserDataTable = twitter.FetchProfile(); // error here 
     } 
    } 
} 

答えて

1

をチェックするTweetinviは、あなたがしたい正確に何をしてサンプルプロジェクトを提供します:https://github.com/linvi/tweetinvi/tree/master/Examplinvi.Webhttps://github.com/linvi/tweetinvi/wiki/Authentication:あなたがここにもtweetinviでの認証についての詳細を見つけることができます

https://github.com/linvi/tweetinvi/blob/master/Examplinvi.Web/Controllers/HomeController.cs#L14-L36

私はラインあなたに興味があるだろうと強調しています。ここで

を使用すると、ASP.NET認証を使用するスニペットです:

private IAuthenticationContext _authenticationContext; 

// Step 1 : Redirect user to go on Twitter.com to authenticate 
public ActionResult TwitterAuth() 
{ 
    var appCreds = new ConsumerCredentials("CONSUMER_KEY", "CONSUMER_SECRET"); 

    // Specify the url you want the user to be redirected to 
    var redirectURL = "http://" + Request.Url.Authority + "/Home/ValidateTwitterAuth"; 
    _authenticationContext = AuthFlow.InitAuthentication(appCreds, redirectURL); 

    return new RedirectResult(authenticationContext.AuthorizationURL); 
} 

public ActionResult ValidateTwitterAuth() 
{ 
    // Get some information back from the URL 
    var verifierCode = Request.Params.Get("oauth_verifier"); 

    // Create the user credentials 
    var userCreds = AuthFlow.CreateCredentialsFromVerifierCode(verifierCode, _authenticationContext); 

    // Do whatever you want with the user now! 
    ViewBag.User = Tweetinvi.User.GetAuthenticatedUser(userCreds); 
    return View(); 
} 
関連する問題