Pergunta

I have followed the directions exactly, copied code examples - I cannot get this to respond (write an event on a calendar). Please help - if there is any help for me. AFter 12 hours of working on this with a huge deadline of tomorrow, I'm about to pull my hair out.

On Google Developer Console, created a project and generated keys required. The keys below are altered for safety. None of the echos are showing except for the first one with the order number in it. My programmer got this code to work, so I know it's OK - it's something set up wrong on the console, but I need a clue:

Full code - like I said, it's been tested and works on another project.

    if(isset($_GET['orderid']) )
    {
        $_SESSION['oid']= $_GET['orderid'];

    }
echo $_GET['orderid'];
$client = new Google_Client();
$client->setApplicationName("API Project");
$client->setClientId('9999999999999.apps.googleusercontent.com');
$client->setClientSecret('xxxxxxxxxxxxxxxxxxxxxxxxx');

$scriptUri = "http://".$_SERVER["HTTP_HOST"].$_SERVER['PHP_SELF'];
$client->setRedirectUri($scriptUri);

//$client->setDeveloperKey('AIxxxxxxxxxxxxx'); - SERVER APPS
$client->setDeveloperKey('AIxxxxxxxxxxxxxxx'); // - WEB APPS 


$cal = new Google_CalendarService($client);
if (isset($_GET['logout'])) {
 unset($_SESSION['token']);
}

if (isset($_GET['code'])) {
 echo $_GET['code'];
 $client->authenticate($_GET['code']);
 $_SESSION['token'] = $client->getAccessToken();
 header('Location: http://' . $_SERVER['HTTP_HOST'] .      $_SERVER['PHP_SELF']);
}

if (isset($_SESSION['token'])) {
 echo $_SESSION['token'];
 $client->setAccessToken($_SESSION['token']);
}

if ($client->getAccessToken()) {
$calList = $cal->calendarList->listCalendarList();
//print "<h1>Calendar List</h1><pre>" . print_r($calList, true) . "</pre>";
$_SESSION['token'] = $client->getAccessToken(); 

// database access is here and like I said, it is tested and working

echo "<center>Event has successfully added to Your Google Calendar...</center>";
unset($_SESSION['oid']);


} else {
  $authUrl = $client->createAuthUrl();

  print "<a class='login' href='$authUrl'>Click Here for Google Authorization!</a>";
}
Foi útil?

Solução

If you just want to add an event on Google Calendar (no other interactions), I think you should use the direct link :

https://www.google.com/calendar/render?action=TEMPLATE&text=Your+event+title&dates=20140325T090000Z/20140325T100000Z&details=Your+event+description&location=Room+12&pli=1&uid&sf=true&output=xml

You just have to customize variables and escape non-URI characters.

** EDIT **

Do you successfully connect the user through OAuth 2?

** EDIT 2 **

Your code is working for me without the DB access :

if ($client->getAccessToken()) {
    $calList = $cal->calendarList->listCalendarList();
    //print "<h1>Calendar List</h1><pre>" . print_r($calList, true) . "</pre>";
    $_SESSION['token'] = $client->getAccessToken(); 

    // DB ACCESS 

    echo "<center>Event has successfully added to Your Google Calendar...</center>";
    unset($_SESSION['oid']);
} else {
    $authUrl = $client->createAuthUrl();
    print "<a class='login' href='$authUrl'>Click Here for Google Authorization!</a>";
}

Julian

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top