简体   繁体   中英

The remote server returned an error: (400) Bad Request.

I am trying to make a facebook open graph api call from inside by web application.I am making a web request using a C# request like this.

string token = "q2Fe0utty5gzCasPL23...";
string url = "https://graph.facebook.com/me?access_token=" + 
    HttpUtility.UrlEncode(token) +"&response_type=id";

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

Stream receiveStream = response.GetResponseStream();
StreamReader readStream = newStreamReader(receiveStream,Encoding.UTF8);
string responseData = readStream.ReadToEnd();

_context.SaveChanges();

As the token has some special characters(+,/,==) in it i have encoded it using HttpUtility.UrlEncode(token) but still i get the following error.

The remote server returned an error: (400) Bad Request.

How do i go about fixing this error. I did the above things by seeing some response in stack-overflow, but still getting the error.Where did i go wrong?

As the token has some special characters(+,/,==)

That sounds strange … usually access tokens consist of letters, numbers and maybe a pipe symbol.

And if you make a request with a non-valid access token (not meaning expired, but a token that could not be decoded at all), then you'll get a 400 response.

So please check your token in the debug tool, https://developers.facebook.com/tools/debug

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM