2014-05-12 3 views
0

웹 API 컨트롤러 내에서 LinqToTwitter 라이브러리를 통해 트위터에 질의를 한 후 코드 실행이 중단되고 웹 API 동작이 응답을 반환하지 못하는 문제가 있습니다. 나는 아마 웹 api와 linqToTwitter 사이에 일종의 충돌이있을 것이라고 생각하지만, 나는 여기서 완전히 우둔합니다. 내 트위터 래퍼 파일이 사용하는 문했다LinqToTwitter 쿼리 후 웹 API가 응답을 반환하지 않습니다.

[HttpPost] 
public HttpResponseMessage CreateNewInterview(Model.NewInterview interview) 
    { 
     // find twitter Id 
     var twitterId = new Twitter().RetrieveTwitterId(interview.SubjectTwitterName);// nothing is returned here and nothing executes below 


     // assign model 
     var model = new NewInterview 
      (interview.Title, twitterId, DateTime.Now, interview.PublicQuestions, interview.Category); 

     // create the new interview 
     Admin.createInterview(model); 

     // create response 
     return Request.CreateResponse(HttpStatusCode.OK); 
    } 
+0

'AuthTool' 클래스를 어떻게 만들었나요? –

답변

0

:

using System; 
using System.Collections.Generic; 
using System.Configuration; 
using System.Data.Entity;// <-- Had to remove this one!!! 
using System.Linq; 
using System.Threading.Tasks; 
using System.Web; 
using System.Web.Mvc; 
using LinqToTwitter; 
using LinqToTwitter.Security; 
using TwitterTools; 

가 모호한 오류를 일으켰습니다

// This class is my wrapper for linqToTwitter 
public class Twitter 
{ 

// FIELDS 
    private readonly MvcAuthorizer _auth; 

    // PROPERTIES 
    public TwitterContext Twit 
    { 
     get 
     { 
      return new TwitterContext(_auth); 
     } 
    } 
public Twitter() 
    { 
     // all keys 
     var cKey = ConfigurationManager.AppSettings[ 
      "twitConsumerKey"]; 
     var cSecKey = ConfigurationManager.AppSettings[ 
      "twitConsumerSecret"]; 
     var oToken = AuthTool.getUserTwitterTokens().token; 
     var oTokenSecc = AuthTool.getUserTwitterTokens() 
      .tokenSecret; 

     ICredentialStore cred = new InMemoryCredentialStore(); 
     cred.ConsumerKey = cKey; 
     cred.ConsumerSecret = cSecKey; 
     cred.OAuthToken = oToken; 
     cred.OAuthTokenSecret = oTokenSecc; 

     // get auth 
     _auth = new MvcAuthorizer() 
       { 
        CredentialStore = cred 
       }; 
    } 

// This is the specific method called from within the web api action 
public string RetrieveTwitterId(string twitName) 
{ 
    // this statement executes a successful linqToTwitter query as verified with fiddler 
    // but doesn't return anything to the user variable. The rest of the code does not execute. 
    var user = Twit.User.SingleOrDefault 
     (x => x.Type == UserType.Show && 
       x.ScreenName == twitName); 

    if(user != null) 
    { 
     return user.UserID.ToString("F0"); 
    } 
    return null; 
} 
} 

이 호출되는 웹 API를 작업입니다 : 여기에 코드입니다 . 그래도 이것이 원래 코드에서 왜 발생했는지 완전히 이해하지 못합니다.