I am designed a website for facebook data access and while i was accessing it at localhost:4999 port but when ever the page loads then error comes
public class FacebookLoginHelper
{
public Dictionary<string,> GetAccessToken(string code, string scope,string redirectUrl)
{
Dictionary<string,> tokens = new Dictionary<string,>();
string clientId = FacebookApplication.Current.AppId;
//FacebookContext.Current.AppId;
string clientSecret = FacebookApplication.Current.AppSecret;
string url = string.Format("https://graph.facebook.com/oauth/access_token?client_id={0}&redirect_uri={1}&client_secret={2}&code={3}&scope={4}",
clientId, redirectUrl, clientSecret, code, scope);
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));
}
}
return tokens;
}
}
Now it shows error 400 at line : using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
What is the reason ? Please help me o开发者_C百科ut ?
Thanks
A 400 Bad Request Error is returned by the Facebook API when one of the parameters isn't valid for the request you're trying to do, you could try manually pasting the requested URL on your browser along with the parameters, it should display the reason of the error as a JSON (On Chrome or Firefox), Something like this for example:
{
"error": {
"type": "OAuthException",
"message": "redirect_uri isn't an absolute URI. Check RFC 3986."
}
From that point on, you can check what's wrong and fix it.
精彩评论