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

嗯,这可能是一个迂回的答案。但也许您可以查看适用于 windows phone 7 的开源 4square 应用程序:http:
//4square.codeplex.com/

由于您可以查看源代码,因此您可以了解它们是如何与 4sq API 交互的 :-)

于 2010-12-16T15:28:19.763 回答
4

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

于 2011-04-09T13:17:45.667 回答