Question

At the moment I am working with the Facebook API and ASP.Net (MVC4).

Is it possible to post a certain message on my Facebook Wall and receive that message in my web application?

I already tried the next code, but it doesn't work:

Maybe somebody has a solution? (Also I don't want the posts of the news feed, but of my profile wall)

JsonObject fbJsonFeedObj = (JsonObject)fbApp.Get(" https://graph.facebook.com/me/home?fields=from,message,name,picture&access_token=" + token);

string str = fbApp.Get("/me/feed").ToString();
JObject obj = JObject.Parse(str);
JToken jUser = obj["data"];
int numb = jUser.Count();

//Get latest post
int id_post = 0;
string stringMsg = obj["data"][id_post]["likes"].ToString();

Update: I just want a method that gets the latest posts of my personal FB wall. How to accomplish this?

Update 2: Today I tried:

JsonObject fbJsonFeedObj = (JsonObject)fbApp.Get(" https://graph.facebook.com/" + FacebookModel.TestFacebookID + "/feed?access_token=" + token);

With this code I can get the latest post, but how do I split it in a readable string? So I only get the UserId who send the post and the real (string) message?

Update 3: At the moment I am using this code to get the wall posts:

  var wall = (JsonObject)fbApp.Get("/me/feed");

But Visual Studio shows this error:

An active access token must be used to query information about the current user.

I am using the next method to receive the accesstoken:

 public static string GetAccessToken()
        {
            var fb = new FacebookClient();
            dynamic result = fb.Get("oauth/access_token", new
            {
                client_id = FACEBOOK_APP_ID,
                client_secret = FACEBOOK_SECRET,
                grant_type = "client_credentials"
            });
            return result.access_token;
        }

How to solve this problmen?

Was it helpful?

Solution

The initial problem is that you were using /home and not /feed.

/home - The user's news feed.
/feed - The user's wall.

https://developers.facebook.com/docs/reference/api/user/

You can split it the same way you did with the previous (/home) object

//Get latest post
int id_post = 0;
string stringPostId = obj["data"][id_post]["id"].ToString(); //Id of the post
string stringPostSender = obj["data"][id_post]["from"]["name"].ToString(); //Name of sender
string stringPostSenderId = obj["data"][id_post]["from"]["id"].ToString(); //ID of sender

Each object looks like this so you should be able to figure out how to drill down

{
      "id": "5_11111111", 
      "to": {
        "data": [
          {
            "name": "User A", 
            "id": "4"
          }
        ]
      }, 
      "from": {
        "name": "User B", 
        "id": "5"
      }, 
      "message": "This is a test message", 
      "created_time": "2013-10-04T23:01:42+0000"
    }

Your last update is a common mistake many first time developers make.

An application access token should not be used for these calls. You must have a login flow to grant a user access token via OAuth by starting with

https://www.facebook.com/dialog/oauth?
    client_id={app-id}
   &redirect_uri={redirect-uri}

Please read in detail https://developers.facebook.com/docs/facebook-login/login-flow-for-web-no-jssdk/ for an explanation of the process.

Login Flow

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top