Hi,
How i post the feed "I also used the site [my site name]" after user logged in to my drupal site?
Thanks
http://developers.facebook.com/docs/api#publishing
Here is the Solution:
$feed = get_my_feed(); publish_my_message($facebook, $feed); /* * Return array describes how the login window will look like */ function get_my_feed() { global $base_root; $msg = t('My Message!'); $attachment = array( 'name' => t('My Site Name'), 'href' => url( $base_root, array('absolute' => TRUE)), 'description' => t('The description of the attachment'), 'media' => array (array( 'type' => 'image', 'src' => 'path/to/logo.jpg', 'href' => 'link/to/somwhere', )), ); return array('message' => $msg, 'attachment' => json_encode($attachment)); } /* * Return the user facebook info */ function get_me_info($facebook) { $me = null; $session = $facebook->getSession(); // Session based API call. if ($session) { try { //drupal_set_message("Got Session"); $uid = $facebook->getUser(); $me = $facebook->api('/me'); } catch (FacebookApiException $e) { error_log($e); } } else { //drupal_set_message("No Session"); } return $me; } /* * Publish the message on the wall */ function publish_my_message($facebook, $feed) { $session = $facebook->getSession(); $me = $facebook->api('/me'); publish_stream($facebook, $session, $feed); return $me; } /* * a wrapper for the stream.publish facebook method */ function publish_stream($facebook, $session, $feed) { $userid = $facebook->getUser(); $access_token = $session['access_token']; $facebook->api(array('method'=>'stream.publish', 'message'=> $feed['message'], 'attachment' => $feed['attachment'], 'target_id'=>$userid, 'uid'=>$userid, 'access_token'=>$access_token) ); }
Can I just put this PHP script into a rule that get's evaluated after the user logs in first time? Or where should I put this? I basically want to trigger the "Publish to Facebook" field just like after saving a node.
Thanks! Urs
Comments
Comment #1
vectoroc commentedhttp://developers.facebook.com/docs/api#publishing
Comment #2
chenop commentedHere is the Solution:
Comment #3
chenop commentedComment #4
magahugu commentedCan I just put this PHP script into a rule that get's evaluated after the user logs in first time? Or where should I put this? I basically want to trigger the "Publish to Facebook" field just like after saving a node.
Thanks!
Urs