问题
I'm trying to send an application-generated request between two users without going through the JavaScript UI.
FacebookClient client = new FacebookClient(SessionSecret);
Dictionary<string, string> parameters = new Dictionary<string, string>();
parameters["message"] = "Test";
parameters["data"] = "test";
client.PostCompleted += new EventHandler<FacebookApiEventArgs>(testCompleted);
client.PostAsync(String.Format("{0}/apprequests", ID), parameters);
My testCompleted method FacebookApiEventArgs error is always a null object reference on a stream object that it is expecting:
at System.IO.StreamReader..ctor(Stream stream, Encoding encoding, Boolean
detectEncodingFromByteOrderMarks, Int32 bufferSize)
at System.IO.StreamReader..ctor(Stream stream)
at Facebook.FacebookClient.ProcessResponse(HttpHelper httpHelper, Stream
responseStream, Type resultType, String& responseStr, Exception& exception, Boolean&
cancelled)
This is on 5.2.1.
Am I doing it wrong? I've also tried instantiating the client using the App ID and secret with the same results.
It looks like a bug in the Facebook client code in the PrepareRequest method at line 1671:
if (httpMethod == HttpMethod.Get)
{
// for GET, all parameters goes as querystrings
input = null;
queryString.Append(FacebookUtils.ToJsonQueryString(parameters));
}
else
{
if (parameters.ContainsKey("access_token"))
{
queryString.AppendFormat("access_token={0}", parameters["access_token"]);
parameters.Remove("access_token");
}
It's only putting in the parameters passed to the method for Get calls, not for post.
回答1:
I went down a rabbit hole, but I didn't need to. In fact, the problem lies in the fact that I was using the users accessToken instead of generating a new accessToken from the application id and applications secret. The first line should instead be:
FacebookClient client = new FacebookClient(AppId, AppSecret);
来源:https://stackoverflow.com/questions/7654379/application-generated-apprequests-failing-in-silverlight