2010-12-16 15 views
2

私は知っているかもしれません.NET C#のためのfoursquare sdkです。 私は開発者のリファレンスに基づいていますが、私はトークンの要求中にそれを行うことができませんでした、私はエラーを取得し続けます。 私はVS 2008と開発中のサーバーを使用しています。私はこのエラーの前にURLの書き換えのために検索しますが、私はIISでホストされていませんし、web.configもチェックしています。助けてください、ありがとう。フォースクエア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

答えて

4

まあ、これは答えのロータリー一種かもしれません。しかし、多分あなたは、Windowsの電話7のためのオープンソースの4squareアプリをチェックアウトすることができます:
http://4square.codeplex.com/

あなたがソースコードを見ることができますので、あなたは彼らが

+0

ありがとう、私はそれを試してみます。 – falcon

4

:-) 4sq APIとのインタフェースされているかを確認することができますSharpSquare - FourSquare SDK for .NET http://www.igloolab.com/sharpsquare/

+0

私たちはこのライブラリを弊社で使用しようとしました。ライブラリは特定の領域に欠けています(複数のリクエストのサポート、会場のカテゴリが適切にデシリアライズされないなど)ため、Sharpsquareのコードをカスタムコードに書き直すことになりました。少なくとも現在の形では、このライブラリをお勧めできません。 –

+1

その後、プルリクエストはどうですか? – Christoph