There is no invite friends block available, I have enabled all the neccesary modules and went through the documentation, as per documentation a block should be available after following the steps but none is available, Facebook Connect works just fine and so does the like button and so on. is there a certain path I can use in the menu to make "Invite friends" menu link?

Comments

Desi Raaj’s picture

anyone has this working? I would appreciate any help :)

visuaLatte’s picture

I know what's wrong. The fb_friend module is not yet updated for Drupal 7. It uses hook_block instead of hook_block_info. I did some upgrading myself, and it didn't work completely, but I'll post the code when I get a chance-- it'll at least be a head-start.

Nathan

sol roth’s picture

Can't wait to see the code, even if you get it partially ready I've love to see it. I will be needing this feature soon.

visuaLatte’s picture

OK-- here it is. As I said, I still couldn't get it working, but I did split the hook_block() into hook_block_info() and hook_block_view(). Here is the resulting code.

/**
 * Implementation of hook_block_info().
 *
 * Blocks include
 * - Invite friends to install the application.
 * - Invite friends to visit the page currently being browsed.
 * - Show which friends are already users of the current application.
 *
 */

function fb_friend_block_info() {
  $blocks = array();
	$blocks['fb_friend_invite_page'] = array(
		'info' => t('Invite Facebook friends to current page'),
		'status' => 1,
		'region' => '',
		'cache' => DRUPAL_NO_CACHE,
		'visibility' => BLOCK_VISIBILITY_LISTED,
		'pages' => ''
	);
	$blocks['fb_friend_invite_app'] = array(
		'info' => t('Invite Facebook friends to install the current app'),
		'status' => 1,
		'region' => '',
		'cache' => DRUPAL_NO_CACHE,
		'visibility' => BLOCK_VISIBILITY_LISTED,
		'pages' => ''
	);
	$blocks['fb_friend_authorized'] = array(
		'info' => t('Facebook friends who have authorized the current app'),
		'status' => 1,
		'region' => '',
		'cache' => DRUPAL_NO_CACHE,
		'visibility' => BLOCK_VISIBILITY_LISTED,
		'pages' => ''
	);
  return $blocks;
}
  
function fb_friend_block_view($delta = '') {

	switch ($delta) {
	  case 'fb_friend_invite_page':
			$blocks['subject'] = 'Invite friends to visit this page';
			$blocks['content'] = _fb_friend_block_content($delta);
	  break;
	  case 'fb_friend_invite_app':
			$blocks['subject'] = 'Invite a friend to use Collegesaurus';
			$blocks['content'] = _fb_friend_block_content($delta);
	  break;
	  case 'fb_friend_authorized':
			$blocks['subject'] = 'Friends who use Collegesaurus';
			$blocks['content'] = _fb_friend_block_content($delta);
	  break;
	}
	return $blocks;

}

function _fb_friend_block_content($delta) {

  try { // Calls to facebook can fail.

    // None of our blocks are shown if user is not logged in.
    $fbu = fb_facebook_user();
    if (!$fbu)
      return;

    // Our blocks use current application
    global $_fb, $_fb_app;

    if ($delta == 'fb_friend_invite_page') {
      $content = fb_friend_request_content(
        array(
          'module' => 'fb_friend_invite_page',
          'delta' => 'fb_friend_invite_page',
        ), array(
          'hook' => 'fb_friend_invite_page',
          'invite' => TRUE,
          'action_path' => request_path(), // Where sender goes on submit or skip.
          'accept_path' => request_path(), // Where recipient goes on accept.
        ));

      return $content;

    }
    elseif ($delta == 'fb_friend_invite_app') {
      // Exclude users who have already installed.
      $rs = fb_fql_query($_fb, "SELECT uid FROM user WHERE has_added_app=1 and uid IN (SELECT uid2 FROM friend WHERE uid1 = $fbu)"); // FQL not SQL, no {curly_brackets}
      $exclude_ids = array();
      //  Build an delimited list of users...
      if ($rs) {
        foreach ($rs as $data) {
          $exclude_ids[] = $data["uid"];
        }
      }

      $content = fb_friend_request_content(
        array(
          'module' => 'fb_friend_invite_app',
          'delta' => 'fb_friend_invite_app',
          'next' => request_path(),
        ), array(
          'hook' => 'fb_friend_invite_app',
          'invite' => TRUE,
          'title' => variable_get('site_name', $GLOBALS['_fb_app']->title),
          'exclude_ids' => $exclude_ids,
        ));

      return $content;
    }
    elseif ($delta == 'fb_friend_invite_app' && FALSE) {
      // Old way...
      $app_url = url('<front>', array('absolute' => TRUE, 'fb_canvas' => fb_is_canvas()));
      $page_url = url(request_path(), array('absolute' => TRUE, 'fb_canvas' => fb_is_canvas()));
      $site_name = variable_get('site_name', t('application'));
      // Build the alterable data structure.
      // http://wiki.developers.facebook.com/index.php/Fb:request-form
      $fbml = fb_form_requestform(
        array(
          'type' => $site_name,
          'content' => array(
            'markup' => array('#value' => t('You may like this site - <a href="!url">!site</a>.',
                                            array('!url' => $app_url,
                                                  '!site' => $site_name))),
            'choice' => array('#type' => 'fb_form_req_choice',
                              '#attributes' => array(
                                'url' => $app_url,
                                'label' => t('Accept'))),
          ),
          'invite' => TRUE,
          'action' => $page_url,
          'method' => 'POST',
        ));

      // Exclude users who have already installed.
      $rs = fb_fql_query($_fb, "SELECT uid FROM user WHERE has_added_app=1 and uid IN (SELECT uid2 FROM friend WHERE uid1 = $fbu)"); // FQL not SQL, no {curly_brackets}
      // @TODO - confirm new API returns same data structure in $rs!
      $arFriends = '';
      $exclude_ids = '';
      //  Build an delimited list of users...
      if ($rs) {
        $exclude_ids .= $rs[0]["uid"];
        for ( $i = 1; $i < count($rs); $i++ ) {
          if ( $exclude_ids != "" )
            $exclude_ids .= ",";
          $exclude_ids .= $rs[$i]["uid"];
        }
      }

      $fbml['selector'] = fb_form_multi_selector(
        array('actiontext' => t('Invite friends'),
              'exclude_ids' => $exclude_ids,
        ));

      // Allow third-party to modify the form
      drupal_alter('fb_friend_invite_app', $fbml);

      if ($fbml) {
        // Wrap in serverfbml.
        $xfbml = array('#type' => 'fb_form_serverfbml',
                       'fbml' => $fbml);
      }
      // Allow third-party to modify wrapper
      drupal_alter('fb_friend_invite_app_wrap', $xfbml);

      $content = drupal_render($xfbml);
      return array('subject' => t('Invite friends to use !site',
                                  array('!site' => $site_name)),
                   'content' => $content,
      );

    }
    elseif ($delta == 'fb_friend_authorized') {
      if ($fbu = fb_facebook_user()) {
        // Get list of friends who have authorized this app.
        $rs = fb_fql_query($_fb, "SELECT uid FROM user WHERE has_added_app=1 AND uid IN (SELECT uid2 FROM friend WHERE uid1 = $fbu)"); // FQL not SQL, no {curly_brackets}
        // @TODO - confirm the data structure returned from new API still works with this code.
        if (isset($rs) && is_array($rs)) {
          foreach ($rs as $friend_data) {
            $friend_fbu = $friend_data['uid'];
            // TODO: make size and markup configurable
            $content .= "<fb:profile-pic uid={$friend_fbu} size=square></fb:profile-pic>";
          }
        }

        $subject = t('Friends who use !app', array(
                     '!app' => $GLOBALS['_fb_app']->label));  // TODO - fix title

        return $content;
      }
    }	
  }
  catch (Exception $e) {
    // We reach this when Facebook Connect sessions are no longer valid.
    // Javascript should detect this and refresh.  Relatively harmless.
    if (fb_verbose() === 'extreme') {
      fb_log_exception($e, t('Failed to render fb_friend block.'));
    }
  }
  
}
visuaLatte’s picture

Note to my previous post: I usually split hook_block_view out into a separate function (in this case, _fb_friend_block_content($delta)) that has the actual "guts" of the blocks. So hook_block_view() only sets up the blocks and calls this other function.

visuaLatte’s picture

So, does anyone else know how to build upon the code I posted, and why this didn't work? Clearly, even after splitting hook_block() into hook_block_info() and hook_block_view(), it still doesn't enable working blocks inside a Drupal 7 system. There's something else going on within the Facebook Friends module that I am missing. Sorry not to be of more help!

grasmash’s picture

@nateeanes

Disable and uninstall fb_friend.
Change the fb_friend.info file to reflect core = "7.x"
enable module.

That will make the blocks appear. Then you'll have to deal with the updating the database calls. Probably much more too.

Desi Raaj’s picture

any progress on this issue?

druvision’s picture

Status: Active » Fixed

The javascript in the following link worked : Solution - Invite FB Friends to my drupal web app. No need for HTTPS. No need to integrate it into the FB app - just paste the script into a block or into your template.

mayur.pimple’s picture

$output .="<script type=text/javascript>  
                        function requestCallback(response) 
                        {
                                      if(response) alert('Your Invitation is send successfully.');
                        }                 
                        function newInvite()
                        {                                   
                                   var receiverUserIds = FB.ui({ 
                                   method : 'apprequests',
                                   message: 'Invite Friends',
                                   title: 'Invite Friends',                                   
                        },requestCallback,               
                        function(receiverUserIds) 
                        {                                                                   
	                        console.log('IDS :' + receiverUserIds);
                        }                                                                                    
                        );                                
 }        </script>";
Dave Cohen’s picture

Status: Fixed » Active

Please don't close issue just because you found useful information on stack exchange. The issue will be fixed when the module and/or documentation is updated.

lauryndbrown’s picture

Was this ever fixed? I'm trying to find a solution to inviting friends to a website using this module.

sadist’s picture

I need this feature too. Any help here?

squinternata’s picture

Issue summary: View changes

is it possible to know it this module work and how????????

amittarkar’s picture

Whats the current status of this "Invite friends" functionality .after 1st August 2018 thats after the change in facebook's policy.