Hi guys, I am having an issue.
When I get an error on this code it outputs the error twice even though the function I call kills the response, notice the OutputError:
private dynamic GetOauthTokens(string code)
{
Dictionary<string, string> tokens = new Dictionary<string, string>();
string url = string.Format("https://graph.facebook.com/oauth/access_token?client_id={0}&redirect_uri={1}&client_secret={2}&code={3}",
myAppId, HttpUtility.UrlEncode(myLoginRedirectUrl), myAppSecret, code);
try
{
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
StreamReader reader = new StreamReader(response.GetResponseStream());
string retVal = reader.ReadToEnd();
foreach (string token in retVal.Split('&'))
{
tokens.Add(token.Substring(0, token.IndexOf("=")),
token.Substring(token.IndexOf("=") + 1, token.Length - token.IndexOf("=") - 1));
}
}
}
catch (Exception exception)
{
OutputError("Code", exception.Message);
}
return tokens;
}
and here is where I handle it:
protected void OutputError(string error, string message)
{
object obj = new { Status = false, Error = error, Message = message };
string objJson = JsonConvert.SerializeObject(obj);
myHttpContext.Response.Write("LinkedLook.getJson(" + objJson + ");");
myHttpContext.Response.End();
}
For some reason it spits it out twice… what am I doing wrong?