Guest User

Untitled

a guest
Jun 27th, 2012
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. Facebook publish stream directly using PHP
  2. //Note that you will need to have the access token which is what gives permission to write.
  3. function self_fb_post($to_uid,$acToken) {
  4. global $fb; //this is the fb object
  5. $result = false;
  6. $feed_dir = '/'.$to_uid.'/feed/'; //to the UID you want to send to
  7. $message_str = 'Why does facebook development not have decent support';
  8. $msg_body = array('access_token' => $acToken,
  9. 'name' => 'My wall post',
  10. 'message' => $message_str,
  11. 'caption' => "www.mysite.com",
  12. 'link' => 'http://www.mysite.com',
  13. 'description' => 'A wall post which is used to express the frustration of working with crappy facebook developer documentation',
  14. 'picture' => 'http://farm6.static.flickr.com/1111/some-pic.jpg',
  15. 'actions' => array(array('name' => 'My Site',
  16. 'link' => 'http://www.mysite.com'))
  17. );
  18.  
  19. try {
  20. //this is the API call that does it all
  21. $result = $fb->api($feed_dir, 'post', $msg_body);
  22. }
  23. catch (Exception $e) {
  24. $err_str = $e->getMessage();
  25. }
  26.  
  27.  
  28. return $result;
  29. }
  30.  
  31. $facebook = new Facebook(array(
  32. 'appId' => 'YOUR_APP_ID',
  33. 'secret' => 'YOUR_SECRET_KEY',
  34. 'cookie' => true,
  35. 'domain' => 'www.softwareandfinance.com'
  36. ));
  37.  
  38. $permissions = $facebook->api("/me/permissions");
  39. if(! array_key_exists('publish_stream', $permissions['data'][0]) ) {
  40. header( "Location: " . $facebook->getLoginUrl(array("scope" =>
  41. "publish_stream")) );
  42. }
Advertisement
Add Comment
Please, Sign In to add comment