2010-12-16 74 views
2

我知道有沒有.NET C#的任何四方sdk。 我正在做基於開發人員參考,但我沒有做到這一點在請求令牌期間,我不斷收到錯誤。 我正在使用VS 2008和正在開發的服務器。我搜索此錯誤之前,因爲URL重寫,但我不是託管在IIS中,我也有檢查web.config,也沒有運氣。請幫忙,謝謝。Foursquare SDK for .net

這是我的錯誤:用於訪問路徑「/登錄」

的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 2010-12-16 13:28:58

回答

4

好,這可能是一種迂迴的某種答案。但是,也許你可以看看開源4square應用程序爲Windows Phone 7:
http://4square.codeplex.com/

既然你可以看一下源代碼,你可以看到他們是如何與4SQ的API接口:-)

+0

謝謝,我會試試看。 – falcon 2010-12-17 03:16:18

4

SharpSquare - 用於.NET的FourSquare SDK http://www.igloolab.com/sharpsquare/

+0

我們試過在我們公司使用這個庫。我們最終將Sharpsquare代碼重寫爲自定義代碼,因爲該庫缺乏某些區域(沒有多個請求支持,場地類別不能正確反序列化等問題)。我不能推薦這個圖書館,至少目前的形式。 – 2011-06-10 21:25:17

+1

那麼拉請求呢? – Christoph 2013-12-09 09:36:38