400 Bad Request When Publishing a user's score through Facebook SDK for Unity

倾然丶 夕夏残阳落幕 提交于 2019-12-24 00:56:44

问题


I am using Unity3D 4.3.4 Editor and Facebook SDK for Unity 5.1 which allows for testing inside the Editor. I am able to suceesfully post screenshots of my game, but I am struggling trying to post a score.

I based my code on this two samples: Facebook Graph API and Facebook SDK Unity Tutorial . In the callback method when I inspect the result object, I get:

400 Bad Request

If I change the method from POST to GET, I don't get the error, but the score is not posted either. But at least I know the score and access_token are being sent.

Here is what the Proxy (Fiddler) captures, but I was unable to capture the POST, only the GET.

GET /me/scores?score=89&access_token=CAAIx1MAZCucgBAEh8LvPA5A4JGuUBSAre0WGhQRZC11WHEgFh1KQJNnsbOEjN5ppeqfumfazmS6CIrZCRlJEKNVhU9wtZCJJ66d3sJqBQYyAbSpBnNIrLN70hJ91uJbEXRD1HwITbViziv9ZC1vhLleyKOILrN97DItP1DnGbzP0y0xoKmVA4RN42Shb716EUEY49wZBlsXXXXXX& HTTP/1.1

Here is my code:

private IEnumerator PostHighScore() 
{
yield return 0;
int highScore;
highScore = (int)LevelGenerator.Instance.distance;
Dictionary<string, string> wwwForm = new Dictionary<string, string>();
wwwForm["score"] = highScore.ToString();
Log("Just about to POST to /me/scores");
FB.API("/me/scores", Facebook.HttpMethod.POST, PostHighScoreCallback, wwwForm);
}

回答1:


I was able to fix the problem. It was very hard to figure it out because the result object of type FBResult only exposes only 3 properties: A string Text that was coming empty, an Image in the form of a Texture2D also empty and a string Error that only showed "400 Bad Request". I was unable to intercept the response on my proxy Fiddler. See here for more info on FBResult

Luckily Mono Developer allowed me to see the private parts of the FBResult object and expanding the data I found a property called responseHeaderString which showed a more detailed error returned on the header.

The error was:

WWW-Authenticate: OAuth "Facebook Platform" "invalid_request" "(#3) Method allowed only for games"

From there I easily found that I needed to go to my App Details on Facebook and change the Category to Games. Since my Facebook was in Spanish, when I created my App I had chosen Entertainment since "Juegos" was not listed, you need to scroll and it is not obvious.

I wanted to share this information since even though you may be facing a completely different problem, knowing that inspecting the FBResult object from Mono Developer will help you find out the reason in the response headers.



来源:https://stackoverflow.com/questions/23357531/400-bad-request-when-publishing-a-users-score-through-facebook-sdk-for-unity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!