2010-12-16 4 views
2

나는 .NET C#을위한 foursquare sdk가 있는지 알고 있습니다. 개발자 참조를 기반으로하고 있지만 토큰을 요청하는 도중에 오류가 발생했습니다. 오류가 계속 발생합니다. VS 2008 및 개발중인 서버를 사용하고 있습니다. URL 재 작성 때문에이 오류가 발생하기 전에 검색하지만 IIS에서 호스트되지 않았으며 web.config도 확인했습니다. 도와주세요, 고마워요.에 대한 Foursquare SDK

이 내 오류입니다 : '/ 로그인'경로에 액세스하는 데 사용

는 HTTP 동사 POST 허용되지 않습니다.

이 내 구현 :

 HttpWebRequest request = null; 

     HttpWebResponse response = null; 

     StreamReader responseStream = null; 

     ASCIIEncoding ascii = null; 
     string key = ConfigurationManager.AppSettings["key"]; 
     string secret = ConfigurationManager.AppSettings["secret"]; 
     string callback = ConfigurationManager.AppSettings["callback"]; 

     string obtainTokenUrl = ConfigurationManager.AppSettings["obtainTokenUrl"]; 

     try 
     { 
      string postData = "client_id=" + key + "&response_type=code&redirect_uri=" + callback; 

      ascii = new ASCIIEncoding(); 
      byte[] postBytes = ascii.GetBytes(postData); 

      try 
      { 
       request = WebRequest.Create(obtainTokenUrl) as HttpWebRequest; 
      } 
      catch (UriFormatException) 
      { 
       request = null; 
      } 

      if (request == null) 
      { 
       throw new ApplicationException("Invalid URL: " + obtainTokenUrl); 
      } 

      request.Method = "POST"; 
      request.ContentType = "application/x-www-form-urlencoded"; 
      request.ContentLength = postBytes.Length; 

      //add post data to request 
      Stream postStream = request.GetRequestStream(); 
      postStream.Write(postBytes, 0, postBytes.Length); 
      postStream.Close(); 

      response = (HttpWebResponse)request.GetResponse(); 
      Encoding encode = Encoding.GetEncoding("utf-8"); 
      responseStream = new StreamReader(response.GetResponseStream(), encode); 

      Response.Write(responseStream.ReadToEnd()); 
+1

자신을 oauth로 코딩하고 있습니까? 이 작업을 수행하는 훌륭한 라이브러리가 있습니다. 또한 비슷한 오래된 질문이있다. http://stackoverflow.com/questions/3611731/foursquare-oauth-authentication-net-sample – Rup

답변

4

음,이 대답의 교차로 종류의 수 있습니다. 소스 코드를 볼 수 있기 때문에
http://4square.codeplex.com/

, 당신은 그들이

+0

고마워, 나는 그것을 시도 할 것이다. – falcon

4

도 :-) 4sq API와 인터페이스하는 방법을 볼 수 있습니다하지만 어쩌면 당신은 윈도우 폰 7에 대한 오픈 소스 4square 응용 프로그램을 확인할 수 있습니다 SharpSquare - .NET 용 FourSquare SDK http://www.igloolab.com/sharpsquare/

+0

우리 회사에서이 라이브러리를 사용해 보았습니다. 라이브러리가 특정 영역에서 부족하기 때문에 (Sharpsquare 코드를 사용자 정의 코드로 다시 작성하는 것은 끝났습니다 (다중 요청 지원, 장소 범주가 제대로 직렬화 해제되지 않음 및 기타 문제점). 적어도 현재의 형태에서는이 라이브러리를 추천 할 수 없습니다. –

+1

그럼 풀 요청은 어떻습니까? – Christoph