0

Using Facebook Toolkit i am able to get data of user. But is it possible to post data on Facebook page and get data from Facebook page. Please provide me the relevant code for posting on Facebook Page.

1
  • Himanshu, could you be more specific on what exactly you're trying to do, and how far you've already gotten ? Commented Apr 22, 2014 at 17:56

1 Answer 1

2

The first thing you would do would be to obtain the Facebook page ID - this is simply the bit of the page URL after https://www.facebook.com/ - so, the Developer Force Facebook page ID is forcedotcom.

Now, to get the posts (feed) for that page:

posts = new FacebookPosts(accessToken, pageid +'/feed', null);

To post to that page:

FacebookPublish.postToWall(accessToken, pageid, new Map<String, String>{'message' => message});

You can edit the sample page controller in the Facebook Toolkit to try this out - look for myPosts and postToFeed() and change me to a page ID:

public FacebookPosts myPosts {
    get {
        try {
            String accessToken = getAccessToken();

            if (accessToken != null) {
                myPosts = new FacebookPosts(accessToken, 'forcedotcom/feed', null);
            }               
        } catch (Exception e) {
            error = e.getMessage();
        }

        return myPosts;
    } set;
}

// Further down...

public PageReference postToFeed() {
    error = null;

    try {
        if (message != null) {
            FacebookPublish.postToWall(getAccessToken(), 'forcedotcom', new Map<String, String>{'message' => message});
        }

        message = null;
    } catch (Exception e) {
        error = e.getMessage();
    }

    return null;
}
4
  • thanks, HI now i need to send private message to other users of facebook from salesforce. I am able to send message using Java Script SDK from salesforce, but the message look like message This attachment may have been removed or the person who shared it may not have permission to share it with you. I want to send direct message using graph api. help.
    – Himanshu
    Commented Apr 23, 2014 at 5:14
  • You can't send a direct message using the graph api. It's not possible - see salesforce.stackexchange.com/a/33365/67
    – metadaddy
    Commented Apr 23, 2014 at 6:00
  • When i am sending message using Java Script SDK i am able to send message but also getting an warning message along with my message. Warning or Error is as : This attachment may have been removed or the person who shared it may not have permission to share it with you. How can i remove the warning message.
    – Himanshu
    Commented Apr 23, 2014 at 6:43
  • Answered on your other question.
    – metadaddy
    Commented Apr 23, 2014 at 13:58

Not the answer you're looking for? Browse other questions tagged .