diff --git a/app/Http/Controllers/LearnController.php b/app/Http/Controllers/LearnController.php index f47ae32f342ccf8de59dfff1e3f5653d2be525b7..34d524b4d975b95f957a2fc78e329b07ae597217 100644 --- a/app/Http/Controllers/LearnController.php +++ b/app/Http/Controllers/LearnController.php @@ -34,56 +34,31 @@ class LearnController extends Controller */ public function new() { - echo 'nyampe1'; + // Initialize $client = LearnController::getClient(); $service = new \Google_Service_Sheets($client); - echo 'nyampe 2'; + // Create Spreadsheet $spreadsheet = new \Google_Service_Sheets_Spreadsheet([ 'properties' => [ 'title' => 'Testing' ] ]); - echo 'nyampe 3'; $response = $service->spreadsheets->create($spreadsheet, ['fields' => 'spreadsheetId']); - echo 'nyampe'; - $data = array( - 'role' => 'owner', - 'type' => 'user', - 'emailAddress' => 'piscokn@gmail.com' - ); - - echo $response->spreadsheetId; + // Edit permission $service2 = new \Google_Service_Drive($client); $permission2 = new \Google_Service_Drive_Permission([ 'role' => 'writer', - 'type' => 'user', - 'emailAddress' => 'piscokn@gmail.com' + 'type' => 'anyone' ]); - // $permission2->setValue('piscokn@gmail.com'); - // $permission2->setType('user'); - // $permission2->setRole('owner'); $response2 = $service2->permissions->create($response->spreadsheetId, $permission2); - // # Create a connection - // echo $response->spreadsheetId . '\n'; - // $url = 'https://www.googleapis.com/drive/v3/files/' . $response->spreadsheetId . '/permissions'; - // echo $url; - // $ch = curl_init($url); - // # Form data string - // $postString = http_build_query($data, '', '&'); - // # Setting our options - // curl_setopt($ch, CURLOPT_POST, 1); - // curl_setopt($ch, CURLOPT_POSTFIELDS, $postString); - // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - // # Get the response - // $responsee = curl_exec($ch); - // curl_close($ch); - - // echo $responsee; - // return view('welcome'); - // printf("Spreadsheet ID: %s\n", $spreadsheet->spreadsheetId); + if (empty($response->spreadsheetId)) { + echo "Pembuatan Gagal"; + } else { + return $response->spreadsheetId; + } } /** diff --git a/app/Http/Controllers/a.php b/app/Http/Controllers/a.php deleted file mode 100644 index dc934042bff5d6b7ab68e1d233fff23ac426c9b5..0000000000000000000000000000000000000000 --- a/app/Http/Controllers/a.php +++ /dev/null @@ -1,76 +0,0 @@ -<?php -require __DIR__.'/../../../vendor/autoload.php'; - -if (php_sapi_name() != 'cli') { - throw new Exception('This application must be run on the command line.'); -} - -/** - * Returns an authorized API client. - * @return Google_Client the authorized client object - */ -function getClient() -{ - $client = new Google_Client(); - $client->setApplicationName('Datalearn'); - $client->setScopes(\Google_Service_Sheets::SPREADSHEETS); - $client->setAuthConfig('e3.json'); - $client->setAccessType('offline'); - $client->setPrompt('select_account consent'); - - - // Load previously authorized token from a file, if it exists. - // The file token.json stores the user's access and refresh tokens, and is - // created automatically when the authorization flow completes for the first - // time. - $tokenPath = 'token.json'; - if (file_exists($tokenPath)) { - $accessToken = json_decode(file_get_contents($tokenPath), true); - $client->setAccessToken($accessToken); - } - - // If there is no previous token or it's expired. - if ($client->isAccessTokenExpired()) { - // Refresh the token if possible, else fetch a new one. - if ($client->getRefreshToken()) { - $client->fetchAccessTokenWithRefreshToken($client->getRefreshToken()); - } else { - // Request authorization from the user. - $authUrl = $client->createAuthUrl(); - printf("Open the following link in your browser:\n%s\n", $authUrl); - print 'Enter verification code: '; - $authCode = trim(fgets(STDIN)); - - // Exchange authorization code for an access token. - $accessToken = $client->fetchAccessTokenWithAuthCode($authCode); - $client->setAccessToken($accessToken); - - // Check to see if there was an error. - if (array_key_exists('error', $accessToken)) { - throw new Exception(join(', ', $accessToken)); - } - } - // Save the token to a file. - if (!file_exists(dirname($tokenPath))) { - mkdir(dirname($tokenPath), 0700, true); - } - file_put_contents($tokenPath, json_encode($client->getAccessToken())); - } - return $client; -} - - -// Get the API client and construct the service object. -$client = getClient(); -$service = new Google_Service_Sheets($client); - -// Prints the names and majors of students in a sample spreadsheet: -// https://docs.google.com/spreadsheets/d/1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms/edit -$spreadsheet = new \Google_Service_Sheets_Spreadsheet([ - 'properties' => [ - 'title' => 'Testin' - ] - ]); -$response = $service->spreadsheets->create($spreadsheet, ['fields' => 'spreadsheetId']); - echo 'nyampe 4'; - echo $response->spreadsheetId; \ No newline at end of file diff --git a/app/Http/Controllers/cre1.json b/app/Http/Controllers/cre1.json deleted file mode 100644 index e87d346a4e7af140c563accc7a31e731de2eab69..0000000000000000000000000000000000000000 --- a/app/Http/Controllers/cre1.json +++ /dev/null @@ -1 +0,0 @@ -{"web":{"client_id":"1038840787003-olj0fj86t5t0g4rlsree58eh3knq2atk.apps.googleusercontent.com","project_id":"datalearn","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"u3hi8Sa59C6QAfInptyncvYd","javascript_origins":["http://localhost:8000"]}} \ No newline at end of file diff --git a/app/Http/Controllers/credentials1.json b/app/Http/Controllers/credentials1.json deleted file mode 100644 index 30ca0b3525f47397454be508ff35c1f027dc07a2..0000000000000000000000000000000000000000 --- a/app/Http/Controllers/credentials1.json +++ /dev/null @@ -1 +0,0 @@ -{"web":{"client_id":"596977500283-23ka11e3cvdkqn74gum49huse2os9hvo.apps.googleusercontent.com","project_id":"quickstart-1586270192915","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"EilEhMA3QrB3T0o4AV9rNuux","javascript_origins":["http://localhost:8000"]}} \ No newline at end of file diff --git a/app/Http/Controllers/credentials2.json b/app/Http/Controllers/credentials2.json deleted file mode 100644 index 30ca0b3525f47397454be508ff35c1f027dc07a2..0000000000000000000000000000000000000000 --- a/app/Http/Controllers/credentials2.json +++ /dev/null @@ -1 +0,0 @@ -{"web":{"client_id":"596977500283-23ka11e3cvdkqn74gum49huse2os9hvo.apps.googleusercontent.com","project_id":"quickstart-1586270192915","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"EilEhMA3QrB3T0o4AV9rNuux","javascript_origins":["http://localhost:8000"]}} \ No newline at end of file diff --git a/app/Http/Controllers/e3.json b/app/Http/Controllers/e3.json deleted file mode 100644 index 5e3859f38c6f3753dbf67be1b8114dbbc0ef45b9..0000000000000000000000000000000000000000 --- a/app/Http/Controllers/e3.json +++ /dev/null @@ -1 +0,0 @@ -{"installed":{"client_id":"596977500283-7put6bokjiqf0r63vb52ksja3umpssc7.apps.googleusercontent.com","project_id":"quickstart-1586270192915","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"Pm5stg2CPDYlRvIJFYq2QZel","redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"]}} \ No newline at end of file diff --git a/app/Http/Controllers/token.json b/app/Http/Controllers/token.json deleted file mode 100644 index 4b62849a5deff339609fdb99b1eee65f7468f505..0000000000000000000000000000000000000000 --- a/app/Http/Controllers/token.json +++ /dev/null @@ -1 +0,0 @@ -{"access_token":"ya29.a0Ae4lvC0gzsPFpKrZaTMsmIJBn_Nhm5wVKXY2Lyy7A1kzxeCUZmiUdz5rH0ty4eRqTKD9g3SJskJMbQ203ufXWNCEPZao6v86JiZ5OvYe81zp2QP31xqpmiZcPSBfUADat5rvNeZLSfAjvtUHKuL0s6-HiLbPLQCOA1M","expires_in":3599,"refresh_token":"1\/\/0gemlmny29IG1CgYIARAAGBASNwF-L9Ir10D1ArUamttBe9ZBrrOu0-O4VfPwS927GKRWVJB0xMLAa3hRJbsiVm7pU6kEpyId7a4","scope":"https:\/\/www.googleapis.com\/auth\/spreadsheets","token_type":"Bearer","created":1586279916} \ No newline at end of file diff --git a/resources/views/redirect.blade.php b/resources/views/redirect.blade.php deleted file mode 100644 index ca5cafc16ec9ba3372c4b6d9f3a95c9658566c77..0000000000000000000000000000000000000000 --- a/resources/views/redirect.blade.php +++ /dev/null @@ -1,45 +0,0 @@ -<?php - session_start(); - // init configuration - $clientID = '1038840787003-n9lfv6h5tg3pdu38c6lksvkvivl1geor.apps.googleusercontent.com'; - $clientSecret = 'n9qmB0e0811fHzW4jgMBhAh7'; - $redirectUri = 'http://localhost:8000/redirect.php'; - - // create Client Request to access Google API - $client = new Google_Client(); - $client->setApplicationName("Datalearn"); - $client->setClientId($clientID); - $client->setClientSecret($clientSecret); - $client->setRedirectUri($redirectUri); - $client->addScope("email"); - $client->addScope("profile"); - - // authenticate code from Google OAuth Flow - if (isset($_GET['code'])) { - // $token = $client->fetchAccessTokenWithAuthCode($_GET['code']); - // $client->setAccessToken($token['access_token']); - - // // get profile info - // $google_oauth = new \Google_Service_Oauth2($client); - // $google_account_info = $google_oauth->userinfo->get(); - // $email = $google_account_info->email; - // $name = $google_account_info->name; - $client->authenticate($_GET['code']); - $_SESSION['access_token'] = $client->getAccessToken(); - header('Location: ' . filter_var($redirectUri, FILTER_SANITIZE_URL)); - if (isset($_SESSION['access_token']) && $_SESSION['access_token']) { - $client->setAccessToken($_SESSION['access_token']); - } - echo 'berhasil'; - // get profile info - $google_oauth = new Google_Service_Oauth2($client); - $google_account_info = $google_oauth->userinfo->get(); - $email = $google_account_info->email; - $name = $google_account_info->name; - echo $name; - echo $email; - // now you can use this profile info to create account in your website and make user logged in. - } else { - echo "<a href='".$client->createAuthUrl()."'>Google Login</a>"; - } -?> \ No newline at end of file diff --git a/resources/views/test.blade.php b/resources/views/test.blade.php index 81804a6e391932c84ba6b28a120c85f9aea1d2cb..414b5415d945f1c67190653dbbd0df3f9a24e33c 100644 --- a/resources/views/test.blade.php +++ b/resources/views/test.blade.php @@ -1,4 +1,4 @@ <iframe style="width:100%; height:500px;overflow:auto;" - src="https://docs.google.com/spreadsheets/d/1vSRP2St6tvX-dL9U1uXoyEf9ipDXEyh8_6D1KeH8N_U/edit?usp=sharing&single=true&widget=true&headers=false"> + src="https://docs.google.com/spreadsheets/d/1gkSt69nwGC4DMyoFvaJgHcA6rGlMXDXWGmnLGiF7xXY/edit?usp=drivesdk&rm=embedded"> </iframe> \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 6b0953e0da8e3545cf976efebcb9fb107441d5ef..9399f995976f12e7f0d4fc7e6135d07e87a5a4a1 100644 --- a/routes/web.php +++ b/routes/web.php @@ -17,9 +17,6 @@ Route::get('/', function () { Route::get('/test', function () { return view('test'); }); -Route::get('/redirect.php', function () { - return view('redirect'); -}); Auth::routes(); Route::get('/home', 'HomeController@index')->name('home');