Bonjour à tous,
Bon après quelques jours de recherche, je viens quémander votre savoir.
J'essaie de récupérer les événements de mon agenda via l'Api Google calendar.
Depuis une page php simple j'y arrive plus ou moins, mais avec symfony j'ai une erreur de "key Invalid". je suppose donc que je fais mal mon authentification.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
 
namespace App\Controller;
 
use App\Entity\Client;
use App\Form\ClientType;
use Google_Service_Calendar;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
 
 
 
/**
 * @Route("/client")
 */
class ClientController extends AbstractController
{
        /**
         * @Route("/", name="client_index", methods={"GET"})
         */
        public function index(): Response
    {
 
        function getClient(){
 
            $client = new \Google_Client();
            $client -> setApplicationName ( "test06/11" );
            $client ->setClientId("$clientId");
            $client ->setDeveloperKey("$developperKey");
            $client->setAuthConfig('./client-secret_id.json ');
            $client->addScope(\Google_Service_Calendar::CALENDAR);
            $client->setAccessType('offline');
 
            $redirect_uri = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
            $client->setRedirectUri($redirect_uri);
            if(isset($_GET[$code]))
            {
                $client->fetchAccessTokenWithAuthCode($_GET[$code]); //code de vérification
            }
            return $client;
        }
 
        // Get the API client and construct the service object.
        $client = getClient();
        $service = new Google_Service_Calendar($client);
 
        // Print the next 10 events on the user's calendar.
        $calendarId = 'primary';
        $optParams = array(
            'maxResults' => 10,
            'orderBy' => 'startTime',
            'singleEvents' => true,
            'timeMin' => date('c')
        );
        $results = $service->events->listEvents($calendarId, $optParams);
        $events = $results->getItems();
 
        if (empty($events)) {
            print "No upcoming events found.\n";
        } else {
            print "Upcoming events:\n";
            foreach ($events as $event) {
                $start = $event->start->dateTime;
                if (empty($start)) {
                    $start = $event->start->date;
                }
                printf("%s (%s)\n", $event->getSummary(), $start);
            }
        }
        return $this->render('client/index.html.twig', [
            'service' => $service,
            'client' => $client,
        ]);
    }
Je vous remercie d'avance.
P.S. Je suis débutant soyez cool !