I'm studying google slide API on laravel framework now. i want to create a simple template at first but i stuck. i got this error.
{ "error": { "code": 401, "message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.", "errors": [ { "message": "Login Required.", "domain": "global", "reason": "required", "location": "Authorization", "locationType": "header" } ], "status": "UNAUTHENTICATED", "details": [ { "@type": "type.googleapis.com/google.rpc.ErrorInfo", "reason": "CREDENTIALS_MISSING", "domain": "googleapis.com", "metadata": { "service": "slides.googleapis.com", "method": "google.apps.slides.v1.PresentationsService.CreatePresentation" } } ] } }
I've been following the tutorial to obtain the OAuth credential with file .json on https://console.cloud.google.com and store it to folder "storage > app" folder
{"web":{"client_id":"xxx.apps.googleusercontent.com","project_id":"xxx","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":"xxx","redirect_uris":["mydomain"],"javascript_origins":["mydomain"]}}
and here is my code
<?php
namespace App\Http\Controllers;
use Google\Client as GoogleClient;
use Google\Service\Slides;
use Google\Service\Slides\BatchUpdatePresentationRequest;
use Google\Service\Slides\Presentation;
use Google\Service\Slides\CreateSlideRequest;
use Google\Service\Slides\LayoutPlaceholderIdMapping;
use Google\Service\Slides\InsertTextRequest;
class SlideController extends Controller
{
public function index()
{
$credentialsPath = storage_path('app/slide-api-credential.json');
$client = new GoogleClient();
$client->setAuthConfig($credentialsPath);
$client->addScope('Slides::PRESENTATIONS');
$slides = new Slides($client);
$presentation = new Presentation([
'title' => 'My First Slide'
]);
$slideRequests = [
new CreateSlideRequest([
'slideLayoutReference' => [
'predefinedLayout' => 'BLANK'
],
'placeholderIdMappings' => [
new LayoutPlaceholderIdMapping([
'objectId' => 'TITLE',
'layoutPlaceholder' => [
'type' => 'TITLE'
]
]),
new LayoutPlaceholderIdMapping([
'objectId' => 'SUBTITLE',
'layoutPlaceholder' => [
'type' => 'SUBTITLE'
]
])
]
]),
new InsertTextRequest([
'objectId' => 'TITLE',
'text' => 'Hello,'
]),
new InsertTextRequest([
'objectId' => 'SUBTITLE',
'text' => 'World!'
])
];
$batchUpdateRequest = new BatchUpdatePresentationRequest([
'requests' => $slideRequests
]);
$createdPresentation = $slides->presentations->create($presentation);
$presentationId = $createdPresentation->presentationId;
$slides->presentations->batchUpdate($presentationId, $batchUpdateRequest);
return "Slide created with ID: $presentationId";
}
}
just create a simple presentation slide. How do i able to solve this? please help