/** * This function is handles the callback from Box API. * @return string */ function _soc_boxauth_get_code_from_box_handler() { // get query string parameters $qs = drupal_get_query_parameters(); watchdog(SOC_BOXAUTH_MODULENAME, "Got code back from Box", $qs, WATCHDOG_INFO); // Stage post data and create http query $post_data = ['grant_type' => 'authorization_code', 'code' => $qs['code'], 'client_id' => variable_get(SOC_BOXAUTH_CLIENTID_VARIABLE), 'client_secret' => variable_get(SOC_BOXAUTH_CLIENTSECRET_VARIABLE)]; $result = BoxFolderOperations::doPost('https://api.box.com/oauth2/token', $post_data, 'Content-type: application/x-www-form-urlencoded', 'QUERY'); // save to session. Decoded json object into php array $_SESSION['box'] = drupal_json_decode($result); $_SESSION['box']['expires_time'] = time() + SOC_BOXAUTH_EXPIREOFFSET; // If successful, the ['box']['access_token'] will exists. Log and report // to user. if (isset($_SESSION['box']['access_token'])) { drupal_set_message(t(variable_get(SOC_BOXAUTH_SUCCESSMESSAGE_VARIABLE))); watchdog(SOC_BOXAUTH_MODULENAME, 'Successful box access_token'); $next_steps = variable_get(SOC_BOXAUTH_NEXTSTEPS_VARIABLE, ['value' => t('Next steps...')]); return $next_steps['value']; } else { $message = t(variable_get(SOC_BOXAUTH_FAILUREMESSAGE_VARIABLE)); drupal_set_message($message, 'error'); watchdog(SOC_BOXAUTH_MODULENAME, 'Failed box access_token'); return $message; } }
function _soc_boxauth_diagnostics() { if (!BoxFolderOperations::isSessionActive()) { return 'Box not active'; } $content = '<pre>'; $content .= print_r($_SESSION['box'], true); $folder = new BoxFolder(0, $_SESSION['box']['access_token']); $content .= print_r($folder->getItems(), true); $content .= '</pre>'; return $content; }
function soc_boxgroup_test($gid) { if (!BoxFolderOperations::isSessionActive()) { return 'Box session not active'; } $box_id = BoxFolderOperations::getBoxFolderID($gid); if (!$box_id) { $folder = new BoxFolder($box_id, BoxFolderOperations::getCurrentAccessToken()); } $to_return[] = 'TESTING:'; $to_return[] = $box_id; //$to_return[] = '<pre>' . print_r(json_decode($folder->getCollaborations()), TRUE) . '</pre>'; $to_return[] = '<h2>Collaborators Object</h2><pre>' . print_r($folder->getCollabortiorNames(), TRUE) . '</pre>'; return '<p>' . implode('</p><p>', $to_return) . '</p>'; }
/** * Calls doGet function from the static operations helper file * @param $url * @param $header * @return mixed */ public function doGet($url, $header) { return BoxFolderOperations::doGet($url, $header); }