Question

I am trying to checkin to Foursquare using the API, I have obtained the oauth_token and am doing a POST request with the oauth_token. According to the documentation the endpoint I'm hitting is https://api.foursquare.com/v2/checkins/add. This however returns a 400 Bad Request message. This is my code in C#

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api.foursquare.com/v2/checkins/add?oauth_token"+ oauth_token + "&venueId=" + venueId);

request.Method = "POST";

HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse();

Stream responseStream = webResponse.GetResponseStream();

When I do the same in curl however, it posts a checkin and I get a json response back

curl --data "oauth_token=[oaut_token]&venueId=[venueId]" https://api.foursquare.com/v2/checkins/add

Was it helpful?

Solution

Ultimately what worked is the following:

        using (WebClient wc = new WebClient())
        {
            System.Collections.Specialized.NameValueCollection reqparm = new System.Collections.Specialized.NameValueCollection();
            reqparm.Add("oauth_token", oauth_token);
            reqparm.Add("venueId", venueId);

            byte[] responsebytes = wc.UploadValues(URI, "POST", reqparm);
            string responsebody = Encoding.UTF8.GetString(responsebytes);
        }

Thanks everyone for your help!

OTHER TIPS

You should write your data to request input stream: HttpWebRequest.GetRequestStream()

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top