Facebook应用程序按应用程序名称发布到用户墙(非私人用户名)

时间:2010-12-25 00:37:18

标签: asp.net facebook-c#-sdk

我是facebook环境的新手,我正在开发一个应用程序,在某些条件下应该通过写在墙上来告知用户。

但是墙上的这条消息应该显示为应用程序发布的内容,而不是我。

我尝试了fbApp.Post,fbApp.Api调用,但所有这些都将我显示为发件人。

我尝试了以下内容:

string appAccessTokenPath = String.Format("https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id={0}&client_secret={1}", FacebookSettings.Current.AppId, FacebookSettings.Current.AppSecret); 

string appAccessToken = fbApp.Get(appAccessTokenPath).ToString();

FacebookApp myAppFb = new FacebookApp(appAccessToken);

But I am taking the following exception at call fbApp.Get(....:

Newtonsoft.Json.JsonReaderException was unhandled by user code
  Message=Unexpected character encountered while parsing value: a. Line 1, position 1.
  Source=Newtonsoft.Json
  LineNumber=1
  LinePosition=1
  StackTrace:
       at Newtonsoft.Json.JsonTextReader.ParseValue(Char currentChar) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\JsonTextReader.cs:line 585
       at Newtonsoft.Json.JsonTextReader.ReadInternal() in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\JsonTextReader.cs:line 328
       at Newtonsoft.Json.JsonTextReader.Read() in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\JsonTextReader.cs:line 279
       at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 114
       at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\JsonSerializer.cs:line 421
       at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\JsonSerializer.cs:line 413
       at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\JsonConvert.cs:line 707
       at Facebook.JsonSerializer.DeserializeObject(String json, Type type) in d:\Projects\facebooksdk\Source\Facebook\JsonSerializer.cs:line 92
       at Facebook.JsonSerializer.DeserializeObject(String json) in d:\Projects\facebooksdk\Source\Facebook\JsonSerializer.cs:line 73
       at Facebook.FacebookApp.MakeRequest(HttpMethod httpMethod, Uri requestUrl, Byte[] postData, String contentType, Type resultType, Boolean restApi) in d:\Projects\facebooksdk\Source\Facebook\FacebookApp.cs:line 1004
       at Facebook.FacebookApp.<>c__DisplayClassb.<OAuthRequest>b__a() in d:\Projects\facebooksdk\Source\Facebook\FacebookApp.cs:line 566
       at Facebook.FacebookApp.WithMirrorRetry[TReturn](Func`1 body) in d:\Projects\facebooksdk\Source\Facebook\FacebookApp.cs:line 752
       at Facebook.FacebookApp.OAuthRequest(Uri uri, IDictionary`2 parameters, HttpMethod httpMethod, Type resultType, Boolean restApi) in d:\Projects\facebooksdk\Source\Facebook\FacebookApp.cs:line 566
       at Facebook.FacebookApp.Graph(String path, IDictionary`2 parameters, HttpMethod httpMethod, Type resultType) in d:\Projects\facebooksdk\Source\Facebook\FacebookApp.cs:line 550
       at Facebook.FacebookAppBase.Api(String path, IDictionary`2 parameters, Type resultType, HttpMethod httpMethod) in d:\Projects\facebooksdk\Source\Facebook\FacebookAppBase.cs:line 439
       at Facebook.FacebookAppBase.Get(String path) in d:\Projects\facebooksdk\Source\Facebook\FacebookAppBase.cs:line 473
       at GizemliHayran.Outbox.Page_Load(Object sender, EventArgs e) in C:\Documents and Settings\TUNC TOROSDAGLI\my documents\visual studio 2010\Projects\GizemliHayran\GizemliHayran\Outbox.aspx.cs:line 44
       at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
       at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
       at System.Web.UI.Control.OnLoad(EventArgs e)
       at System.Web.UI.Control.LoadRecursive()
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException: 

2 个答案:

答案 0 :(得分:1)

您必须获取与应用程序关联的访问令牌,而不是用户。您可以在此处查看如何执行此操作:http://developers.facebook.com/docs/authentication/#authenticating-as-an-application

获得应用程序的访问令牌后,只需使用相同的方法发布到墙上,但手动将访问令牌设置为应用程序。

访问令牌始终代表Facebook API上操作的“参与者”。因此,如果您作为一个人发布,则使用他们的访问令牌,如果您要作为应用程序发布,则必须使用该应用程序的令牌。

答案 1 :(得分:0)

我建议你使用codeplex中的facebook C#sdk。这是一个完整的测试代码,从它开始

Facebook C# sdk code samples