Hey guys,
I am trying to use the Google Calendar API within a php webpage to display personal calendar events for each user.
I made it displaying the events, but I'm stuck on displaying the Event Colors for every event.
I was looking around the internet for two days now, and there are only examples for importing new events.

Is there a way to get the background color for every event?

I grabbed all of the events with the getItems() method.
I print that object and it showed me that in all of the events we have no colorIds (NULL).
So I took all of the colors as shown in the last link and there weren't any ID's.
I can't get what is the relation between the Color definition class and the events.

Do I have to assign them manually?
There's my code for now:

$events = $service->events->listEvents('primary');
    $colors = $service->colors->get();
    //$events = $service->events->get('primary', "eventId");
    //print_r($colors->getEvent());

    print_r($events->getItems());

    echo '<div>';
        while(true) {


          foreach ($events->getItems() as $key => $event) {

            foreach($colors->getEvent() as $key1 => $color){
                //echo $color->getBackground() . " - " . $event->getId() . "<br />";
                //echo $color->getBackground();
                if($key == $key1){
                    echo "<p style='background-color:{$color->getForeground()}; width: 20px; height:20px;'></p>";
                }else{
                    continue;
                }
            }
            //echo $key . " ";
            echo '<b>' . $event->getCreator()->getDisplayName() . ':</b> ';
            echo $event->getSummary() . '<br />';
            echo '<b>' . $event->getEnd()->getDate() . '</b>';

          }


          $pageToken = $events->getNextPageToken();
          if ($pageToken){
            $optParams = array('pageToken' => $pageToken);
            $events = $service->events->listEvents('primary', $optParams);
          }
          else{
            break;
          }
        }
    echo '</div>';

Also thank you for the links. I've read them before, but it's always good to go back to ground 0. :)

Ok, it seems that Google have no interest of getting our life comfortable with their opens-source APIs.

Conclusion:
You can't get the color ID if you aren't the creator of the event.

Member Avatar for diafol

Ah. OK now I understand. Didn't realise the users in question were adding to your cal. I assumed that you were adding them yourself. I vaguely remember something about that. That is a PITA but there again, it probably does make sense from the perspective that each user-added event would have to have an 'override' equivalent stored in your calendar if it was modified by you. But then say the user changed the event, should those changes override your change? Etc. Headache.

Oh, you actually have a point there! :)
Only one person should be able to override changes, so I see the logic now! :D
I'll try making a solution and if I figure out something, I will post it here for the others.
Thank you, diafol!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.