Google api v3 calandar quickadd php
Get the solution ↓↓↓I'm trying to create events in my google calendar with the google quickadd API. Here is my code:
require_once 'googleapi/vendor/autoload.php';
$client = new Google\Client();
$client->setApplicationName("Google Calendar API");
$client->setDeveloperKey("AIzaSyDdR3w2J59ZVVv_s7BopzNuteu1Bzo");
$client->setAuthConfig('googleapi/code_secret_client_62725432848-um1gbjoo7iqi1upvmv4niosddfte43.apps.googleusercontent.com.json');
$client->addScope("https://www.googleapis.com/auth/calendar.events");
$service = new Google_Service_Calendar($client);
// echo "<pre>";
// print_r($service);
// echo "</pre>";
$createdEvent = $service->events->quickAdd(
'[email protected]',
'Appointment at Somewhere on June 3rd 10am-10:25am'
);
echo $createdEvent->getId();
I keep getting the error below. Can someone please tell me why?
Fatal error: Uncaught Google\Service\Exception: { "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" } } in C:\xampp\htdocs\google quick add\googleapi\src\Http\REST.php:128 Stack trace: #0 C:\xampp\htdocs\google quick add\googleapi\src\Http\REST.php(103): Google\Http\REST::decodeHttpResponse(Object(GuzzleHttp\Psr7\Response), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...') #1 [internal function]: Google\Http\REST::doExecute(Object(GuzzleHttp\Client), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...') #2 C:\xampp\htdocs\google quick add\googleapi\src\Task\Runner.php(18 in C:\xampp\htdocs\google quick add\googleapi\src\Http\REST.php on line 128
Answer
Solution:
According to error messages you weren't authorized.
these you can read about 401 HTTP code
And these you can see the example, right way to authorize your app
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: cannot add or update a child row: a foreign key constraint fails
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.