diff --git a/og_invite_link.module b/og_invite_link.module
index 795e2a0..b944642 100755
--- a/og_invite_link.module
+++ b/og_invite_link.module
@@ -32,6 +32,12 @@ function og_invite_link_menu() {
     'type' => MENU_CALLBACK,
     'file' => 'og_invite_link.pages.inc',
   );
+  $items['og_invite_link/realname_autocomplete'] = array(
+    'page callback' => 'realname_ajax_autocomplete_user',
+    'access callback' => 'user_access',
+    'access arguments' => array('access content'),
+    'type' => MENU_CALLBACK,
+  );
   $items['admin/og/og_invite_link'] = array(
     'title' => 'Organic groups invitations',
     'description' => 'Configure group invitation settings',
@@ -677,7 +683,12 @@ function og_invite_link_invite_users_to_groups($params) {
       }
 
       // Attempt to load the user
-      if (valid_email_address($name)) {
+      if (module_exists('realname')) {
+        //TODO: problem here if there are multiple realnames.
+        $realname_uid = db_result(db_query("SELECT uid FROM {realname} WHERE realname = '%s'", $name));
+        $account = user_load(array('uid' => $realname_uid));
+      }
+      elseif (valid_email_address($name)) {
         // Load based on email address
         $account = user_load(array('mail' => $name));
       }
diff --git a/og_invite_link.pages.inc b/og_invite_link.pages.inc
index cfa118a..c18c08a 100755
--- a/og_invite_link.pages.inc
+++ b/og_invite_link.pages.inc
@@ -13,6 +13,12 @@ function og_invite_link_invite_page_form($form_state = array(), $nodes) {
   // Set the page title (needed because it's a local task)
   drupal_set_title(t('Invite members to this group'));
 
+  if (module_exists('realname')) {
+    $autocomplete_path = 'og_invite_link/realname_autocomplete';
+  } else {
+    $autocomplete_path = 'og_invite_link/autocomplete';
+  }
+
   $form = array();
   // Handle the case when the form is called from the menu.
   if (is_object($nodes)) {
@@ -27,7 +33,7 @@ function og_invite_link_invite_page_form($form_state = array(), $nodes) {
     '#title' => t('Invitees'),
     '#maxlength' => 1024,
     '#required' => TRUE,
-    '#autocomplete_path' => 'og_invite_link/autocomplete',
+    '#autocomplete_path' => $autocomplete_path,
     '#description' => t('Add one or more usernames or email addresses in order to invite users in this group. Multiple usernames should be separated by a comma. A maximum of !max invites can be sent out at a time.', array('!max' => OG_INVITE_LINK_MAX_INVITES_PER_FORM)),
   );
   $form['additional_message'] = array(
