Neslishah
Neslishah

Reputation: 11

Facebook Application Post to a Users Wall by Application Name (Not private users name)

I am new to facebook environment, and I am working on an application, which in certain conditions should inform users by writing on their walls.

But this message on the wall, should be displayed as posted by the application, not by me.

I tried fbApp.Post, fbApp.Api calls, but all of them displayed me as the sender.

I tried the following:

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: 

Upvotes: 1

Views: 1559

Answers (2)

Bill Berlington
Bill Berlington

Reputation: 2414

I recommend you to use facebook C# sdk from codeplex. Here is a complete tested code for starting with it

Facebook C# sdk code samples

Upvotes: 0

Nate Totten
Nate Totten

Reputation: 8932

You have to get the access token associated with the application, not the user. You can see how to do that here: http://developers.facebook.com/docs/authentication/#authenticating-as-an-application

Once you have the application's access token, just use the same method to Post to the wall, but manually set the access token to the application.

The access token always represents the 'actor' of the action on the Facebook APIs. So if you are publishing as a person, you use their access token, if you are publishing as an app you must use the app's token.

Upvotes: 1

Related Questions