[英]post facebook score 400 bad request
I am try to update a user score on a Facebook leaderboard using the following code: 我尝试使用以下代码在Facebook排行榜上更新用户分数:
string _url = "https://graph.facebook.com/MY_APP_ID/scores";
var _parameters="score=100&access_token=MY_APP_TOKEN_WITH_PUBLISH_ACTION";
WebRequest _request = WebRequest.Create(_url);
_request.Method = "POST";
var _dataArray = Encoding.ASCII.GetBytes(_parameters.ToString());
_request.ContentLength = _dataArray.Length;
using (Stream _dataStream = _request.GetRequestStream())
{
_dataStream.Write(_dataArray, 0, _dataArray.Length);
}
WebResponse _response = _request.GetResponse();
When I try to get the response the application throws an exception: 当我尝试获取响应时,应用程序将引发异常:
The remote server returned an error: (400) Bad Request.
远程服务器返回错误:(400)错误的请求。
What am I doing wrong? 我究竟做错了什么?
I'm actually in the middle of something similar with LinkedIn. 实际上,我在与LinkedIn相似。 Wrap it in a try block and try this exception handler:
将其包装在try块中,然后尝试以下异常处理程序:
catch (WebException webEx) {
StringBuilder sb = new StringBuilder();
sb.AppendLine(webEx.Message);
sb.AppendLine();
sb.AppendLine("REQUEST: ");
sb.AppendLine();
sb.AppendLine(string.Format("Request URL: {0} {1}", webRequest.Method, webRequest.Address));
sb.AppendLine("Headers:");
foreach (string header in webRequest.Headers) {
sb.AppendLine(header + ": " + webRequest.Headers[header]);
}
sb.AppendLine();
sb.AppendLine("RESPONSE: ");
sb.AppendLine();
sb.AppendLine(string.Format("Status: {0}", webEx.Status));
if (null != webEx.Response) {
HttpWebResponse response = (HttpWebResponse) webEx.Response;
sb.AppendLine(string.Format("Status Code: {0} {1}", (int) response.StatusCode, response.StatusDescription));
if (0 != webEx.Response.ContentLength) {
using (var stream = webEx.Response.GetResponseStream()) {
if (null != stream) {
using (var reader = new StreamReader(stream)) {
sb.AppendLine(string.Format("Response: {0}", reader.ReadToEnd()));
}
}
}
}
}
_log.Warn(sb.ToString(), webEx);
throw new Exception(webEx.Message, webEx);
}
That'll at least log what they're returning. 至少会记录他们返回的内容。 In my case, I couldn't reproduce the problem on my system, but QA's servers were getting a ton of 400 Bad Requests.
就我而言,我无法在系统上重现该问题,但是QA的服务器收到了大量的400错误请求。 Turned out they were invalid timestamps because the system clocks were 7 minutes slow, and LinkedIn was rejecting the timestamp.
事实证明它们是无效的时间戳,因为系统时钟慢了7分钟,而LinkedIn拒绝了该时间戳。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.