2

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());
falcon
  • 65
  • 1
  • 10
  • 1
    You're coding up oauth yourself? There are good libraries out that that do this for you. Also there's a similar old question http://stackoverflow.com/questions/3611731/foursquare-oauth-authentication-net-sample – Rup Dec 16 '10 at 13:28

2 Answers2

4

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 :-)

Joel Martinez
  • 46,929
  • 26
  • 130
  • 185
4

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

user232028
  • 113
  • 8
  • We tried using this library at our company. We ended up rewriting the Sharpsquare code into custom code because the library is lacking in certain areas(no multiple request support, venue categories don't deserialize properly, and other issues). I can't recommend this library, at least in its current form. – Frank Rosario Jun 10 '11 at 21:25
  • 1
    How about a pull request then? – Christoph Dec 09 '13 at 09:36