2

.NET C# 用の foursquare SDK があることを知っているかもしれません。私は開発者のリファレンスに基づいてやっていますが、トークンのリクエスト中に失敗しました.エラーが発生し続けます. 私はVS 2008を使用しており、開発中のサーバーです。URLの書き換えのためにこのエラーの前に検索しましたが、IISでホストされておらず、web.configもチェックしていますが、運もありません。助けてください、ありがとう。

これは私のエラーです:

パス '/login' へのアクセスに使用される 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());
4

2 に答える 2

4

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

于 2011-04-09T13:17:45.667 に答える
4

まあ、これは回りくどい答えかもしれません。しかし、Windows Phone 7 用のオープン ソース 4square アプリをチェックしてみてください:
http://4square.codeplex.com/

ソースコードを見ることができるので、それらが 4sq API とどのようにインターフェースしているかを見ることができます :-)

于 2010-12-16T15:28:19.763 に答える