by Dave Cohen: fb_graph() helper function, and pull addition data with user info.
authorDave Cohen
Fri, 6 Jan 2012 01:18:12 +0000 (17:18 -0800)
committerDave Cohen
Fri, 6 Jan 2012 01:18:12 +0000 (17:18 -0800)
fb.module

index 7a3e743..7c1f4ed 100644 (file)
--- a/fb.module
+++ b/fb.module
@@ -434,6 +434,55 @@ function fb_vars() {
   );
 }
 
+/**
+ * Helper function to work with facebook "open" graph.
+ */
+function fb_graph($path, $params, $fb = NULL) {
+  if (!$fb) {
+    $fb = $GLOBALS['_fb'];
+  }
+  $url = url("https://graph.facebook.com/$path", array(
+               'query' => $params,
+             ));
+  $http = drupal_http_request($url);
+
+  if (!isset($http->error) && isset($http->data)) {
+    $data = json_decode($http->data, TRUE);
+    /*
+    // Yes, it's double encoded.  At least sometimes.
+    if (is_string($data)) {
+      $data = json_decode($data, TRUE);
+    }
+    */
+    if (is_array($data)) {
+      if (isset($data['error_code'])) {
+        throw new FacebookApiException($data);
+      }
+    }
+    elseif ($http->data == 'true' || $http->code == 200) {
+      // No problems.
+      // dpm($data, __FUNCTION__ . " $url"); // debug
+    }
+    else {
+      // Never reach this???
+      if (function_exists('dpm')) dpm($http, __FUNCTION__ . " unexpected result from $url"); // XXX
+    }
+    return $data;
+  }
+  else {
+    // Should we throw FacebookApiException, or plain old exception?
+    throw new FacebookApiException(
+      array(
+        'error_msg' => t('fb_graph failed querying !path.  !detail', array(
+                           '!path' => $path,
+                           '!detail' => $http->error,
+                         )),
+        'error_code' => $http->code,
+      ));
+  }
+
+}
+
 
 /**
  * Helper to get the tokens needed to accss facebook's API.
@@ -1414,7 +1463,10 @@ function fb_users_getInfo($oids, $fb = NULL, $refresh_cache = FALSE) {
       $fields = array(
         'about_me',
         'affiliations',
+        'birthday',
         'name',
+        'first_name',
+        'last_name',
         'is_app_user',
         'pic',
         'pic_big',