OK, die Fehlermeldung konnte ich am Handy nicht lesen, aber nun geht es.
Das Problem scheint die „.p12“ Datei zu sein … die Fehlermeldung sagt aus, dass die Datei nicht geöffnet werden kann.
Ist die Datei in Ordnung und liegt die auch in dem Verzeichnis?
Meine Daten die ich verwende findest Du im Anhang.
Und das ist das Skript welches ich dazu verwendet.
<?
// Service Account info
$client_id = 'DeineID.apps.googleusercontent.com.apps.googleusercontent.com';
$service_account_name = 'DeineID@developer.gserviceaccount.com';
$key_file_location = IPS_GetKernelDir()."scripts\\certificates\\DeineP12.p12";
//Kalender 1
$Userid1 = ""; //KalenderID
$Tage1 = 20;
$ShortCut1 = 1;
//Kalender 2
$Userid2 = ""; //KalenderID
$Tage2 = 20;
$ShortCut2 = 2;
//Kalender 3
$Userid3 = ""; //KalenderID
$Tage3 = 20;
$ShortCut3 = 3;
//===============================================================
//Erinnerungsvariablen
$warningtoday = false;
$warningtomorrow = false;
//Hier die Farbe für die ShortCuts angeben
$SC_Farbe[1] = "#BDBDBD";
$SC_Farbe[2] = "#00AD00";
$SC_Farbe[3] = "#DF0101";
//Hier den Style wählen
$blinkToday = true; // (true/false) blinken des heutigen Kalendereintrages An/Aus
/******** Farbnamen, RGB-Formatierung, Hex-Zahlen möglich *********/
$StyleText[1] = "white"; // Textfarbe Datum
$StyleText[2] = "gray"; // Textfarbe Wochentag
/*** xx-small, x-small, small, normal, large, x-large, xx-large ***/
/************** oder Angabe in pt - z.B. "12pt" *******************/
$StyleText[3] = "15pt"; // Textgröße Datum
$StyleText[4] = "15pt"; // Textgröße Wochentag
$StyleText[5] = "14pt"; // Textgröße Termintitel
$StyleText[6] = "12pt"; // Textgröße Terminbeschreibung
/****************** Ab hier wieder die Finger lassen **************/
// Wochentage auf Deutsch
$tag[0] = "Sonntag";
$tag[1] = "Montag";
$tag[2] = "Dienstag";
$tag[3] = "Mittwoch";
$tag[4] = "Donnerstag";
$tag[5] = "Freitag";
$tag[6] = "Samstag";
$deco = "";
if($blinkToday)$deco = "blink";
//###########################################################################################################################
$refresh = date("d.m.Y, H:i");
if($Userid1 != ""){$calc1 = ReadCalendar($Userid1, $Tage1, $ShortCut1);
if(empty($calc1)){$calc1 = array();}}
else{$calc1 = array();}
if($Userid2 != ""){$calc2 = ReadCalendar($Userid2, $Tage2, $ShortCut2);
if(empty($calc2)){$calc2 = array();}}
else{$calc2 = array();}
if($Userid3 != ""){$calc3 = ReadCalendar($Userid3, $Tage3, $ShortCut3);
if(empty($calc3)){$calc3 = array();}}
else{$calc3 = array();}
$calcData = array_merge($calc1, $calc2, $calc3);
usort($calcData, 'DateCompare');
$calDataTxt = "<table style='border-spacing:0px; width:100%'>"; // Starte Tabellenansicht
$check_date = "";
foreach($calcData as $thisData){
if($thisData['EndeDatum'] != date("d.m.Y", strtotime("yesterday"))){
if($check_date != "" and $thisData['StartDatum'] != $check_date)$calDataTxt .= "</table></th></tr>";
if($thisData['StartDatum'] != $check_date){
if($thisData['StartDatum'] == date("d.m.Y")){
$headerTxt = "Heute";
$warningtoday = true;}
elseif($thisData['StartDatum'] == date("d.m.Y", strtotime("+1 day"))){
$headerTxt = "Morgen";
$warningtomorrow = true;}
else $headerTxt = $thisData['StartDatum'];
$calDataTxt .= "<tr><td style=' padding:5px;
background-color:#444444;
background: -moz-linear-gradient(left, rgba(81,81,81,0) 40%, #282828 100%);
background: -webkit-gradient(linear, left top, right top, color-stop(4%,rgba(40,40,40,0), color-stop(100%,#282828));
background: -webkit-linear-gradient(left, rgba(40,40,40,0) 40%, #282828 100%);
background: -o-linear-gradient(left, rgba(81,81,81,0) 40%, #282828 100%);
background: -ms-linear-gradient(left, rgba(81,81,81,0) 40%, #282828 100%);
background: linear-gradient(to right, rgba(81,81,81,0) 40%), #282828 100%;'>
<span style='color:".$StyleText[1].";font-weight:200;font-size:".$StyleText[3]."'>"
.$headerTxt."</span></td>
<td style='text-align:right; width:100px; padding:4px;background-color:#444444'>"
."<span style='color:".$StyleText[2].";font-weight:normal;font-size:".$StyleText[4]."'>"
.$tag[date("w", strtotime($thisData['StartDatum']))].
"<span>"."</td></tr><tr>
<th colspan='2' style='text-align:left;padding-left:20px;padding-right:0px;padding-bottom:10px;padding-top:0px;'>
<table style='border-spacing:0px; width:100%;padding:4px; border:1px solid #444444;'>";
$check_date = $thisData['StartDatum'];
$calDataTxt .= SetEintrag($thisData);
}
else{
$calDataTxt .= SetEintrag($thisData);
}
}
}
$calDataTxt .= "</table></th></tr></table></div><div align='right'>aktualisiert am ".$refresh."</div></div>"; // Tabelle schließen
SetValue(CreateVariableByName($_IPS['SELF'], "Termine", 3, "~HTMLBox"), $calDataTxt);
SetValue(CreateVariablebyname($_IPS['SELF'], "Erinnerung heute", 0), $warningtoday);
SetValue(Createvariablebyname($_IPS['SELF'], "Erinnerung morgen", 0), $warningtomorrow);
$calDataTxt = '';
foreach($calcData as $thisData)
if($_IPS['SENDER'] == "Execute"){
echo $calDataTxt;
}
function CreateVariableByName($id, $name, $type, $profile = "")
{
global $IPS_SELF;
$vid = @IPS_GetVariableIDByName($name, $id);
if($vid === false)
{
$vid = IPS_CreateVariable($type);
IPS_SetParent($vid, $id);
IPS_SetName($vid, $name);
if($profile !== "") { IPS_SetVariableCustomProfile($vid, $profile); }
}
return $vid;
}
function SetEintrag($thisData){
global $tag, $SC_Farbe, $deco, $StyleText;
if($thisData['StartZeit'] == "00:00"){
if($thisData['StartDatum'] == $thisData['EndeDatum'])$thisData['StartZeit'] = "";
else $thisData['StartZeit'] = "bis ".substr($tag[date("w", strtotime($thisData['EndeDatum']))],0,2).", ".$thisData['EndeDatum'];
}
else if($thisData['StartZeit'] == $thisData['EndeZeit'])$thisData['StartZeit']=$thisData['StartZeit']." Uhr";
else $thisData['StartZeit'] .= " - ".$thisData['EndeZeit']." Uhr";
if($thisData['Beschreibung'] != ""){
$Beschreibung = "<tr><td><span style='font-weight:normal;font-style:italic;font-size:".$StyleText[6].";text-decoration:".$deco.";color:#A4A4A4'> ".$thisData['Beschreibung']."
</span></td></tr>";
}
else{$Beschreibung = "";}
if($thisData['StartDatum'] == date("d.m.Y")){
return "<tr><td><span style='font-weight:large;font-size:".$StyleText[5].";text-decoration:".$deco.";color:".$SC_Farbe[$thisData['shortCut']]."'>".$thisData['StartDatum']."</span></td>
<td style='text-align:right;'>
<span style='font-weight:nromal;font-size:".$StyleText[5].";text-decoration:".$deco.";color:".$SC_Farbe[$thisData['shortCut']]."'>".$thisData['Titel']."</span></td></tr>".$Beschreibung;
}
else{
return "<tr><td><span style='font-weight:large;font-size:".$StyleText[5].";color:".$SC_Farbe[$thisData['shortCut']]."'>".$thisData['Titel']."</span></td>
<td style='text-align:right'>
<span style='font-weight:normal;font-size:".$StyleText[5].";color:".$SC_Farbe[$thisData['shortCut']]."'>".$thisData['StartZeit']."</span></td></tr>".$Beschreibung;;
}
}
function ReadCalendar($calName, $maxDays, $shortCut){
Global $client_id, $service_account_name, $key_file_location;
require_once "google-api-php-client/autoload.php";
$client = new Google_Client();
$client->setApplicationName("Kalender");
$service = new Google_Service_Calendar($client);
$key = file_get_contents($key_file_location);
$cred = new Google_Auth_AssertionCredentials($service_account_name, array('https://www.googleapis.com/auth/calendar'), $key);
$client->setAssertionCredentials($cred);
// Convert recurring events to single events
// Look for events in the next week - now to now+1week
$params = array( 'singleEvents' => TRUE,
'timeMin' => (new DateTime())->format(DateTime::RFC3339),
'timeMax' => (new DateTime())->add(new DateInterval('P' .$maxDays .'D'))->format(DateTime::RFC3339),);
$events = $service->events->listEvents($calName, $params);
//print_r ($events->getItems());
$c = 0;
foreach ($events->getItems() as $event)
{
$Ergebnis[$c]['StartDatum'] = fmt_gdate($event->getStart());
$Ergebnis[$c]['StartZeit'] = fmt_gtime($event->getStart());
$Ergebnis[$c]['EndeDatum'] = fmt_gdate($event->getEnd());
$Ergebnis[$c]['EndeZeit'] = fmt_gtime($event->getEnd());
$Ergebnis[$c]['Titel'] = iconv('UTF-8', 'ISO-8859-1',$event->getSummary());
$Ergebnis[$c]['Beschreibung'] = iconv('UTF-8', 'ISO-8859-1',$event->getDescription());
$Ergebnis[$c]['Ort'] = iconv('UTF-8', 'ISO-8859-1',$event->getLocation());
$Ergebnis[$c]['shortCut'] = $shortCut;
if($Ergebnis[$c]['StartZeit'] == "00:00" && $Ergebnis[$c]['EndeZeit'] == "00:00")
{
$Ergebnis[$c]['EndeDatum'] = date("d.m.Y", strtotime($Ergebnis[$c]['EndeDatum']."-1 day"));
}
$c++;
}
@usort($Ergebnis, 'DateCompare');
return $Ergebnis;
}
function fmt_gdate( $gdate )
{
if ($val = $gdate->getDateTime())
{
return (new DateTime($val))->format( 'd.m.Y' );
}
else if ($val = $gdate->getDate())
{
return (new DateTime($val))->format( 'd.m.Y');
}
}
function fmt_gtime( $gdate )
{
if ($val = $gdate->getDateTime())
{
return (new DateTime($val))->format( 'H:i' );
}
else if ($val = $gdate->getDate())
{
return ('00:00');
}
}
function DateCompare($a, $b)
{
if ( strtotime($a['StartDatum']) == strtotime($b['StartDatum']) ) return 0;
if ( strtotime($a['StartDatum']) < strtotime($b['StartDatum']) ) return -1;
return 1;
}
?>
Sieht dann so aus:
Gruß
Manfred
google-api-php-client.zip (670 KB)