I have a problem with obtaining access token from FourSquare for my C# desktop app. I registered my app at their site and obtained the client id and secret id. For my callback url I put http..localhost:8080. I didn't know what to put, I know it doesn't make much sense but there it is.
I found a way to obtain access token with my browser. When I try the following url:
https://foursquare.com/oauth2/authenticate?client_id=MY_CLIENT_ID&response_type=token&redirect_uri=https:localhost:8080/
it tries to redirect to:
http:localhost:8080/?accsess_token=OBTAINED_ACCSESS_TOKEN
So there you go, I got my access token. Now, I tried to do some similar thing in my C# code by watching the response headers from my C#, and in the Location header there should be:
http:localhost:8080/?accsess_token=OBTAINED_ACCSESS_TOKEN
But I have a problem there is no Location header in the response. When I watch the response header in HttpFox in my browser there is a Location header with my link inside the response.
I have posted here what I have done so far, and I am hitting a brick wall here. If anyone knows any other way to obtain an access token for a desktop app from FourSquare, or has a solution for the problem with headers above. Please post it. If anyone has an answer for this I'll buy him a beer because this is a part of my assignment for a job. :)
Here is my code so far.
string url = "https://foursquare.com/oaut2/authenticate?client_id=E4HFYP1LRDSAL21WJVJ1EBT1NSG1DPRHSNXN0PFI10UIOX0N&response_type=token&redirect_uri=https:localhost:8080/";
HttpWebRequest request = null;
HttpWebResponse response = null;
try
{
request = WebRequest.Create(url) as HttpWebRequest;
response = request.GetResponse() as HttpWebResponse;
request.AllowAutoRedirect = false;
int status = (int)response.StatusCode;
Console.WriteLine("Request headers: ");
Console.WriteLine("-------------------------------------------------------------");
foreach (string s in request.Headers)
{
Console.WriteLine(s + ": " + request.Headers[s]);
}
Console.WriteLine("Response headers: ");
Console.WriteLine("-------------------------------------------------------------");
foreach (string header in response.Headers)
Console.WriteLine(header + ": " + response.Headers[header]);
}
catch (Exception x)
{
Console.WriteLine(x.Message);
}