我一直在搜索有关将评分发布到Facebook应用程序的答案,我仍然无法让它发挥作用。我正在使用的代码在这里 -
private const string FACEBOOK_POST_SCORE_URL = "https://graph.facebook.com/me/scores?access_token={0}";
public void PostScoreAsync(Action<FacebookResponse> response, FacebookScore score)
{
try
{
// Append the user's access token to the URL
Uri fullUri = new Uri(string.Format(FACEBOOK_POST_SCORE_URL, AccessToken));
string json = JsonConvert.SerializeObject(score);
var request = (HttpWebRequest)WebRequest.Create(fullUri);
request.Method = "POST";
request.ContentType = "application/json; charset=utf-8";
using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
{
writer.Write(json);
}
request.BeginGetResponse(WebRequestCallback, new FacebookResult
{
Request = request,
Response = response
});
}
catch (ThreadAbortException)
{
throw;
}
catch (WebException ex)
{
if (response != null)
response(FacebookResponse.NetworkError);
}
catch (Exception ex)
{
if (response != null)
response(FacebookResponse.OtherError);
}
}
我们正在使用webViews而不是iOS / Android Facebook SDK,因为我们正在Mono中构建一个跨平台的应用程序。
显然我有访问令牌&amp;该应用程序似乎具有完全权限,可以执行我想要执行的操作,这是我在登录后允许的。任何想法都赞赏!
答案 0 :(得分:0)
我最终(从同事那里)发现Facebook图形api不会采用json编码的参数,所以我们这样排序 -
string parameters = "score=" + score.Score;
var request = (HttpWebRequest)WebRequest.Create(fullUri);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
{
writer.Write(parameters);
}
现在它工作正常 - 希望这会帮助其他人不会遇到同样的问题。