Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Facebook publish stream directly using PHP
- //Note that you will need to have the access token which is what gives permission to write.
- function self_fb_post($to_uid,$acToken) {
- global $fb; //this is the fb object
- $result = false;
- $feed_dir = '/'.$to_uid.'/feed/'; //to the UID you want to send to
- $message_str = 'Why does facebook development not have decent support';
- $msg_body = array('access_token' => $acToken,
- 'name' => 'My wall post',
- 'message' => $message_str,
- 'caption' => "www.mysite.com",
- 'link' => 'http://www.mysite.com',
- 'description' => 'A wall post which is used to express the frustration of working with crappy facebook developer documentation',
- 'picture' => 'http://farm6.static.flickr.com/1111/some-pic.jpg',
- 'actions' => array(array('name' => 'My Site',
- 'link' => 'http://www.mysite.com'))
- );
- try {
- //this is the API call that does it all
- $result = $fb->api($feed_dir, 'post', $msg_body);
- }
- catch (Exception $e) {
- $err_str = $e->getMessage();
- }
- return $result;
- }
- $facebook = new Facebook(array(
- 'appId' => 'YOUR_APP_ID',
- 'secret' => 'YOUR_SECRET_KEY',
- 'cookie' => true,
- 'domain' => 'www.softwareandfinance.com'
- ));
- $permissions = $facebook->api("/me/permissions");
- if(! array_key_exists('publish_stream', $permissions['data'][0]) ) {
- header( "Location: " . $facebook->getLoginUrl(array("scope" =>
- "publish_stream")) );
- }
Advertisement
Add Comment
Please, Sign In to add comment