setClientId($_POST['client_id']); $client->setClientSecret($_POST['client_secret']); $client->setRedirectUri($_POST['redirect']); $client->setScopes(array('https://www.googleapis.com/auth/drive')); if (isset($_POST['step'])) { $step = $_POST['step']; if ($step == 1) { try { $authUrl = $client->createAuthUrl(); OCP\JSON::success(array('data' => array( 'url' => $authUrl ))); } catch (Exception $exception) { OCP\JSON::error(array('data' => array( 'message' => 'Step 1 failed. Exception: '.$exception->getMessage() ))); } } else if ($step == 2 && isset($_POST['code'])) { try { $token = $client->authenticate($_POST['code']); OCP\JSON::success(array('data' => array( 'token' => $token ))); } catch (Exception $exception) { OCP\JSON::error(array('data' => array( 'message' => 'Step 2 failed. Exception: '.$exception->getMessage() ))); } } } }