I'm trying to get the data from Google spread sheet by using this library: This tutorial, and I follow this tutorial to configure the setup of API and no any error, but once I tried to implement any of the examples they provide in the above link, it show me some errors:
Example 1 (on their link):
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use PulkitJalan\Google\Facades\Google;
use Revolution\Google\Sheets\Sheets;
class SpreadController extends Controller
{
function index()
{
$rows = Sheets::sheet('Sheet 1')->get();
$header = $rows->pull(0);
$values = Sheets::collection($header, $rows);
dd($values);
}
}
The error is:
Unresolvable dependency resolving [Parameter #0 [ array $config ]] in class PulkitJalan\Google\Client
Example 2 (on their link):
Code:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use PulkitJalan\Google\Facades\Google;
use Revolution\Google\Sheets\Sheets;
class SpreadController extends Controller
{
function index()
{
$user = $request->user();
$token = [
'access_token' => $user->access_token,
'refresh_token' => $user->refresh_token,
'expires_in' => $user->expires_in,
'created' => $user->updated_at->getTimestamp(),
];
// all() returns array
$values = Sheets::setAccessToken($token)->spreadsheet('1n0nyJX9wYp-_frg7TzoyMu3WyuSwtCo21g')->sheet('Sheet 1')->all();
}
}
The error is:
Undefined variable: request
This is the config file in the library directory ("vendor/pulkitjalan/google-apiclient/src/config/config.php"):
<?php
return [
/*
|----------------------------------------------------------------------------
| Google application name
|----------------------------------------------------------------------------
*/
'application_name' => env('GOOGLE_APPLICATION_NAME', ''),
/*
|----------------------------------------------------------------------------
| Google OAuth 2.0 access
|----------------------------------------------------------------------------
|
| Keys for OAuth 2.0 access, see the API console at
| https://developers.google.com/console
|
*/
'client_id' => env('GOOGLE_CLIENT_ID', ''),
'client_secret' => env('GOOGLE_CLIENT_SECRET', ''),
'redirect_uri' => env('GOOGLE_REDIRECT', ''),
'scopes' => [],
'access_type' => 'online',
'approval_prompt' => 'auto',
/*
|----------------------------------------------------------------------------
| Google developer key
|----------------------------------------------------------------------------
|
| Simple API access key, also from the API console. Ensure you get
| a Server key, and not a Browser key.
|
*/
'developer_key' => env('GOOGLE_DEVELOPER_KEY', ''),
/*
|----------------------------------------------------------------------------
| Google service account
|----------------------------------------------------------------------------
|
| Set the credentials JSON's location to use assert credentials, otherwise
| app engine or compute engine will be used.
|
*/
'service' => [
/*
| Enable service account auth or not.
*/
'enable' => env('GOOGLE_SERVICE_ENABLED', false),
/*
| Path to service account json file
*/
'file' => env('GOOGLE_SERVICE_ACCOUNT_JSON_LOCATION', '')
],
/*
|----------------------------------------------------------------------------
| Additional config for the Google Client
|----------------------------------------------------------------------------
|
| Set any additional config variables supported by the Google Client
| Details can be found here:
| https://github.com/google/google-api-php-client/blob/master/src/Google/Client.php
|
| NOTE: If client id is specified here, it will get over written by the one above.
|
*/
'config' => [],
];
and .env file contains this assigned values for the config variables:
GOOGLE_APPLICATION_NAME= Append Data
GOOGLE_CLIENT_ID= 995576272219-q9t67ufvehsqoctcq7g.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET= ow1kEPcuSEGmGIXZtl
GOOGLE_REDIRECT=
GOOGLE_DEVELOPER_KEY=
GOOGLE_SERVICE_ENABLED=
GOOGLE_SERVICE_ACCOUNT_JSON_LOCATION=
Can anyone guide me through the solution how I can get the data from spreadsheet or solve the problem considered here.