You are here

function fb_app_set_app_properties in Drupal for Facebook 7.3

Same name and namespace in other branches
  1. 5.2 fb_app.module \fb_app_set_app_properties()
  2. 6.3 fb_app.admin.inc \fb_app_set_app_properties()
  3. 6.2 fb_app.admin.inc \fb_app_set_app_properties()

Sets callback URLs and other properties of a facebook app. Calls the facebook

1 call to fb_app_set_app_properties()
fb_app_admin_form_submit in ./fb_app.admin.inc

File

./fb_app.admin.inc, line 360

Code

function fb_app_set_app_properties($fb_app) {
  $data = fb_get_app_data($fb_app);
  $fb_app_data = $data['fb_app'];

  // Collect properties from all modules.
  $props = fb_invoke(FB_ADMIN_OP_SET_PROPERTIES, array(
    'fb_app' => $fb_app,
  ), array(), FB_ADMIN_HOOK);
  if (count($props)) {
    if ($fb_app_data['set_app_props']) {
      if ($fb = fb_api_init($fb_app)) {
        try {
          $result = fb_graph($fb_app->id, $props + array(
            'access_token' => fb_get_token($fb),
          ), 'POST', $fb);

          // @todo handle $result != true.
          drupal_set_message(t('Note that it may take several minutes for property changes to propagate to all facebook servers.'));
          if (fb_verbose()) {
            drupal_set_message(t('Set the following properties for %label application:<br/><pre>!props</pre>', array(
              '%label' => $fb_app->label,
              '!props' => print_r($props, 1),
            )));
            watchdog('fb_app', 'Set facebook app properties for %label.', array(
              '%label' => $fb_app->label,
            ), WATCHDOG_NOTICE, l(t('view apps'), FB_PATH_ADMIN));
          }

          // Allow third-parties to set additional "properties" such as restrictions.
          fb_invoke(FB_ADMIN_OP_POST_SET_PROPERTIES, array(
            'fb_app' => $fb_app,
            'fb' => $fb,
            'properties' => $props,
          ), array(), FB_ADMIN_HOOK);
        } catch (Exception $e) {
          drupal_set_message(t('Failed to set the following properties for %label application.  You may need to manually editing remote settings!<br/><pre>!props</pre>', array(
            '%label' => $fb_app->label,
            '!props' => print_r($props, 1),
          )), 'error');
          fb_log_exception($e, t('Failed to set application properties on Facebook. %props', array(
            '%props' => json_encode($props),
          )));
        }
      }
    }
    elseif (fb_verbose()) {
      drupal_set_message(t('The following recommended properties for %label application have <strong>not been set automatically</strong>, consider editing remote settings manually:<br/><pre>!props</pre>', array(
        '%label' => $fb_app->label,
        '!props' => print_r($props, 1),
      )), 'warning');
    }
  }
}