You are here

function fb_test_accounts_form in Drupal for Facebook 7.3

Same name and namespace in other branches
  1. 6.3 contrib/fb_test.module \fb_test_accounts_form()
1 string reference to 'fb_test_accounts_form'
fb_test_detail_page in contrib/fb_test.module

File

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

Code

function fb_test_accounts_form($form, &$form_state, $fb_app) {
  try {
    $form['#fb_app'] = $fb_app;
    $fb = fb_api_init($fb_app);
    $result = $fb
      ->api($fb_app->id . "/accounts/test-users", 'GET', array(
      'access_token' => fb_get_token($fb),
    ));
    foreach ($result['data'] as $test_account) {
      $form['#fb_test_accounts'][$test_account['id']] = $test_account;
      $markup = "{$test_account['id']} <a href={$test_account['login_url']} target=_blank>(login)</a>";
      if (isset($test_account['access_token'])) {
        $data = $fb
          ->api($test_account['id'], 'GET', array(
          'access_token' => $test_account['access_token'],
        ));
        if ($data['name']) {
          if (empty($data['link']) && !empty($data['id'])) {
            $data['link'] = 'https://www.facebook.com/profile.php?id=' . $data['id'];
          }
          $markup .= " {$data['name']} (<a href={$data['link']}>profile</a> | <a href=https://graph.facebook.com/{$test_account['id']}?access_token={$test_account['access_token']}>graph (user token)</a> | <a href=https://graph.facebook.com/{$test_account['id']}?access_token=" . fb_get_token($fb) . ">graph (app token)</a>) ";
        }
      }
      $options[$test_account['id']] = $markup;
    }
    if (!empty($options)) {
      $form['checkboxes'] = array(
        '#type' => 'checkboxes',
        '#options' => $options,
      );
    }
    $form['operation'] = array(
      '#type' => 'select',
      '#title' => t('With selected...'),
      '#options' => array(
        'none' => t('please select...'),
        'friends' => t('make friends'),
        'delete' => t('delete account'),
      ),
      '#description' => t('Use caution, there will be no confirmation page.'),
    );
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Submit'),
    );
    $form['header'] = array(
      '#type' => "markup",
      '#value' => "<p>Test Accounts</p>",
      '#weight' => -10,
    );
  } catch (Exception $e) {
    fb_log_exception($e, t('Failed to access test accounts.'));
  }
  return $form;
}