开发者

Foursquare SDK for .net

may i know is there any foursquare sdk for .NET C#. I am doing based on the developer reference but i failed to do it during request for token, i keep on getting the error. I am using VS 2008 and under development server. I search before this error because of url rewriting, but i'm not hosted in IIS and i also have check the web.config, no luck also. Please help, thanks.

This is my error:

The HTTP verb POST used to access path '/login' is not allowed.

This is my implementation:

        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());


Well, this may be a roundabout sort of answer. But maybe you could check out the open source 4square app for windows phone 7:
http://4square.codeplex.com/

Since you can look at the source code, you can see how they are interfacing with the 4sq API :-)


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜