As part of Operation Developer Love, we are are continuing to update our documentation. Recently, I was talking with some developers in New York, and they were surprised to learn that they could publish updates to people who have liked their Open Graph Pages.
You can publish stream updates to people who like your page just like you can with Facebook Pages. There are two ways to get to the publishing interface:
- From your Web page, click Admin Page next to the Like button.
- From Facebook, click "Use Facebook as a Page" under the Account tab or click here.
You can publish stories to people who like your Open Graph Page the same way you write a Facebook post from your own wall. The stories appear in the News Feeds of people who have clicked the Like button on the Open Graph Page.
You can also publish using our API. If you associate your Open Graph Page with a Facebook app using the
fb:app_id meta tag, you can publish updates to the users who have liked your pages via the Graph API.
First you need to get an access token for your app. This can be obtained with:
curl -F type=client_credentials \ -F client_id=your_app_id \ -F client_secret=your_app_secret \ https://graph.facebook.com/oauth/access_token
Using this access token and the URL of your page, you can publish to users via the API with:
curl -F 'access_token=...' \ -F 'message=Hello World!' \ -F 'id=http://www.example.com' \ https://graph.facebook.com/feed
Here is some sample PHP code to help you get started:
<?php $ogurl = "YOUR_OPEN_GRAPH_URL"; $app_id = “YOUR_APP_ID”; $app_secret = "YOUR_APP_SECRET"; $mymessage = urlencode("Hello World!"); $access_token_url = "https://graph.facebook.com/oauth/access_token"; $parameters = "type=client_credentials&client_id=" . $app_id . "&client_secret=" . $app_secret; $access_token = file_get_contents($access_token_url . "?" . $parameters); $apprequest_url = "https://graph.facebook.com/feed"; $parameters = "?" . $access_token . "&message=" . $mymessage . "&id=" . $ogurl . "&method=post"; $myurl = $apprequest_url . $parameters; $result = file_get_contents($myurl); echo "post_id" . $result; ?>
The story will be published with the attribution of your app name (e.g., “GetConnected”).
See our documentation for more info. Post below with any feedback or questions on how we can better help you.