You are here

function fb_test_create_form_submit in Drupal for Facebook 7.3

Same name and namespace in other branches
  1. 6.3 contrib/fb_test.module \fb_test_create_form_submit()

File

contrib/fb_test.module, line 66
http://developers.facebook.com/docs/test_users

Code

function fb_test_create_form_submit($form, &$form_state) {
  $values = $form_state['values'];
  $fb_app = $form['#fb_app'];
  try {
    $fb = fb_api_init($fb_app);
    for ($i = 0; $i < $values['how_many']; $i++) {
      $result = $fb
        ->api($fb_app->id . "/accounts/test-users", 'POST', array(
        'installed' => $values['installed'],
        'permissions' => $values['perms'],
        'access_token' => fb_get_token($fb),
      ));
      if (isset($result['id'])) {
        drupal_set_message(t("Created user !name. Email: %email | Password: %password", array(
          '!name' => "<fb:name uid=" . $result['id'] . "></fb:name>",
          '%email' => $result['email'],
          '%password' => $result['password'],
        )));
      }
    }
    drupal_set_message(t('Created %num test accounts.  Please make note of passwords (they will not be available again).', array(
      '%num' => $values['how_many'],
    )));
  } catch (Exception $e) {
    fb_log_exception($e, t('Failed to create test accounts.'));
  }
}