"Error (405) Method Not Allowed" when calling v2 api

523 views
Skip to first unread message

Devo

unread,
Apr 8, 2011, 6:19:56 PM4/8/11
to foursquare API
Hi folks,

I'm new to the Four Square developer community. I'm playing around
with the apis, but I cannot get a simple search api to work. Here are
the steps I've completed:

1. created a new application on four square (i saved my client_id and
client_secret)
2. created a simple console application in .Net
3. wrote the below function to try and get nearby coffee shops for a
latitude and longitude coordinate:

HttpWebRequest request = null;
HttpWebResponse response = null;
StreamWriter sw = null;
StreamReader sr = null;
string apiUrl = "https://api.foursquare.com/v2/venues/
search";
string responseResult = "";
string ll = "-22.9303205,-43.1812857";
//category id for Coffee Shops.
string categoryId = "4bf58dd8d48988d16d941735";
string clientId = "XXX_MY_CLIENT_ID_XXX";
string clientSecret = "XXX_MY_CLIENT_SECRET_XXX";
string postData = "ll=" + ll + "&categoryId=" + categoryId
+ "&client_id=" + clientId + "&client_secret=" + clientSecret;

//make api request
request = (HttpWebRequest)HttpWebRequest.Create(apiUrl +
"?" + postData);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT
5.1; en-US;) Firefox MyTestApp";
request.Accept = "application/json, application/xml";

//NOTE: When trying to call GetResponse() I get an
exception with the message "Error (405) method not allowed"
response = (HttpWebResponse)request.GetResponse();
sr = new StreamReader(response.GetResponseStream());
responseResult = sr.ReadToEnd();

return responseResult;

Does anyone have any advice on what I am doing wrong?

Thanks.

Akshay Patil

unread,
Apr 8, 2011, 6:43:31 PM4/8/11
to foursqu...@googlegroups.com, Devo
405 == "Method not allowed"

Use GET instead.

~ak
--
Akshay Patil / Foursquare Platform Evangelist
@akdotcom / @foursquareapi


Deven Hariyani

unread,
Apr 8, 2011, 7:06:43 PM4/8/11
to Akshay Patil, foursqu...@googlegroups.com
oh man, I did try using GET before i posted to the forum, but i was still setting the Content-Type to
application/x-www-form-urlencoded
which was causing me to get the error. anyways, i changed the method to GET and removed the Content-Type header, and everything worked beautifully.

thanks for the help!

--
Deven
Reply all
Reply to author
Forward
0 new messages