Problem/Motivation
Today we began seeing this error on a Drupal 6 site with GCal Events:
GCal Events[Upcoming Sidebar] A feed could not be found at http://www.google.com/calendar/feeds/CALENDAR_ID_REDACTED/public/full?max-results=2500&orderby=starttime&singleevents=true&futureevents=true. A feed with an invalid mime type may fall victim to this error, or SimplePie was unable to auto-discover it.. Use force_feed() if you are certain this URL is a real feed.
After looking at the URL for a Calendar of my own, I noticed basic at the end of the URL rather than full. Looking into how the URLs are constructed in code, it references the Google Calendar API v2 documents. This page reads This API is a subject to the Deprecation Policy and will be shutdown on November 17, 2014. Please use APIv3 instead. November 17, 2014 is today. :)
The Drupal 7 version also uses the 2.0 API to construct the calendar feed URL.
Proposed resolution
Use the Google Calendar API v3 to construct the Calendar address instead of v2.
Remaining tasks
Create, review/test, and commit a patch containing the proposed resolution, of course. :)
| Comment | File | Size | Author |
|---|---|---|---|
| #33 | gcal_events.module.txt | 36.64 KB | seplwebmaster |
Comments
Comment #1
younggeezer commentedI'm running 6.x-1.4 and my Gcal event block is dead, Jim. Nice big red error message block on the front page :(
I swapped the /full for /basic (per the modified xml link on the Google calendar details page) and find that the error goes away (evidently a feed of some sort was found), but there are no events shown. A fix would be nice.
Comment #2
guschilds commentedI had the same experience. I swapped /full for /basic and confirmed the fixed feed URL by visiting it in my browser. The error is gone and the block is "fixed", but it doesn't display any of the future events that I've confirmed are in the feed. I'm going to look further into this tomorrow if a fix doesn't arrive faster.
Bumping this in priority, as there are probably many big red errors on front pages. :)
Comment #3
bcarson commentedYup, same as above. A fix would be awesome.
Comment #4
mkamuiru commentedSame issue as well. A patch to display the events would be great. Thanks
Comment #5
djkouza commentedWe are having the same issue as well, tried the 6.x-1.x-dev and 6.x-1.4
Also we found that you need to remove the maxresults (at least on the dev module)
// array_push($calendar_xml_array, "max-results=$num_events", "orderby=starttime", "singleevents=true");
array_push($calendar_xml_array, "orderby=starttime", "singleevents=true");
Gcal_Events is pulling down the google XML as it's showing in the cache folder, but it's not showing anything for the Events blocks. Did Google change the format of it's XML file in addition to altering the API?
Comment #6
wascott commentedditto. We have the same error described above. Funny, I also tried the switch from "/full" to "/basic" in the feed URL and now we have No Events. The Google Calendar API documentation v3 is not very helpful.
I noticed the version was switched from 7 down to 6. Any chance we can get the patch for 7.x 1.x.dev ?
Comment #7
guschilds commentedAttached is the first go at what needs to happen to fix this. It applies to 6.x-1.4 and resolves the problem for us.
There are a few hoops to jump through to use it:
1. It seems that as of v3 you need to register/use a Developer ID key.
To do so:
2. Get the Google API Client Library for PHP.
This means no more Simplepie. I removed all uses of it.
3. Provide your Developer API Key to the block settings.
That should be it.
Please note that there are definitely outstanding issues with this patch. Currently known:
$debug_mode. Need to add it back in if it's deemed necessary.#URL#won't properly be replaced because I wasn't sure where to fetch it from the API.Would be awesome if it evolved into something that could be committed. Thanks ahead of time to all who test and help out!
Comment #8
mgiffordNice to see movement on this. Thanks @guschilds
Comment #9
guschilds commentedConsidering this module is useless without this change, I started looking for others that do the same thing. The best I found is Agenda, but it too uses the API v2 and they've got the same issue, #2376795: Unable to Connect to Google (Calendar API v2 is deprecated). Thought I might as well make the two efforts aware of each other.
It's possible that the Google Calendar Block module uses v3. Not sure at a glance.
Comment #10
jdwfly commentedPatch did not apply cleanly to 6.x-1.x-dev. Could this be rerolled to apply to the dev version?
I'm going to get started for a 7.x version since I need it on my site.
Comment #12
jdwfly commentedI committed a fix to 7.x-1.x-dev. Most of the credit goes to guschilds, thanks a lot. Follow his directions in #7 and it should work for you. I'm running it live on a site right now without issues but please post another issue if something is broken.
Another caveat is that multiple calendars will not work. Also please ensure that you have block caching enabled. If you do not and you have a high traffic site you will break the daily usage limits quite quickly and it will not work the rest of the day.
edit: block caching warning
Comment #13
paardje commentedI applied the Patch, but then i get an empty screen on all pages.
Anny ideas?
Comment #14
sjnorton commentedWe followed the instructions above for 7..x-1.x-dev, and while we no longer get the original error message, we are getting an error "GCal Events: Bad call to list events." I've rechecked the calendar ID, the API key, and cannot find anything wrong. Unfortunately, the error is displaying to the world on a production site even though we have Drupal error display off. Advice appreciated.
Comment #15
jdwfly commented@sjnorton - that error means that the call to request the the calendar failed. Re-check your settings again because that is the most likely culprit.
@paardje - did you apply it to 6.x-1.4 or to 6.x-1.x-dev? Like I already mentioned the patch does not apply cleanly to dev. Sounds like you are getting the WSOD. You might want to restore the module to its state before you applied the patch.
Comment #16
jdwfly commentedHere is the patch reworked against the 6.x-1.x-dev. Sorry but too much has changed since 2009 (6.x-1.4 release) that this really deserves to be patched against the latest dev.
Comment #17
guschilds commentedThanks for rerolling the patch against 6.x-1.x-dev. My initial patch was against 6.x-1.4 because we were using that version and I'd only checked dev long enough to ensure it was also using API v2. I ran out of time to reroll it once I realized how different they were, but I'm glad you were able to use it as the beginning of the 7.x-1.x patch as well as getting it rerolled. Thanks for being so responsive. Sounds like it is in good hands!
Comment #18
jdwfly commentedAdded in the dependency on the libraries module. Also added in the last few variables into the events array so this should be good to go. For those that will look at the patch I did also make quite a few code style changes as well.
Comment #20
djkouza commented@sjnorton - I had the same "Bad Call to list events' issue and Realized I didn't enable the Calendar API on the Google Developer settings. Double check that. Once I fixed that my blocks came right up! Thanks again to @jdwfly and @guschilds for the patches
Comment #21
sjnorton commented@djkouza - That seemed to do it, along with re-entering the API key. Thanks!
Comment #22
paardje commentedjdwfly we use 6.x-1.4.
Comment #23
jdwfly commentedAs soon as I update the readme with the new installation instructions there will be a new release with this fix. Until the dev versions can be used.
Comment #24
younggeezer commentedThanks @guschilds and @jdwfly for the fixes and new version.
Unfortunately, I'm stuck with a "bad call to list events". Google lists Calendar API as enabled. I have generated and entered a server API key. I have the correct (afaik) calendar ID to a public calendar which we've used before. Deleted and re-entered all the above. Same error.
I'd appreciate any suggestions.
--------------
Update: No code problems, just me. Two issues: I had limited queries on my API key to my webserver's IP (v4), but forgot that IPv6 is enabled on my server and that Google uses it. Now I allow queries from any IP. Second issue was that somewhere along the way the '@' in the calendar ID turned into '%40', which is wrong (although I thought the %40 was needed earlier). With these two things fixed, I'm getting events.
Comment #25
JL2014 commentedHi,
Thanks for work, but I have the same "bad call" error/exception:
GCal Events: Bad call to list events
Warning: Invalid argument supplied for foreach() in template_events() (line 710 of ...\gcal_events.module).
I use last versions of drupal 7 and modules (libraries API, google-api-php-client and gcal_events).
I have configured all parameters of the block:
- Developer ID => browser api key and is not over quota (I've also tested server key)
- Calendar ID => x...x@group.calendar.google.com with the good char '@'
- Private ID => x...x is that the code between "private-" and "/basic" (I've also tested the full link)
Have you an idea, please ?
Jean Louis.
-----
Update: with additional trace (in the script) of the exception, I have the URL and "Not Found" error:
https://www.googleapis.com/calendar/v3/calendars/x...x%40group.calendar....
: (404) Not Found
On my chrome browser (not connected to any google account):
- If I try directly the URL, I have also a "Not found (404)" error (tested with %40 or '@').
- If I try directly the URL without the page events?..., I have a "Login Required (401)" error.
- If I try the feeds link as in google settings, the browser returns data (http://www.google.com/calendar/feeds/x...x@group.calendar.google.com/pri...)
The URL "https://www.googleapis.com/calendar/v3..." is it good in google API library ??? why the other URL works ???
Hope that helps.
Comment #26
sinkva commentedSorry, but can you be a little more explicit about where to locate and renaming the Google API Client Library for PHP ?
TIA.
- Tim
Comment #27
JL2014 commentedHi,
Personally, I see that the URL is constructed in 'sites\all\libraries\google-api-php-client\src\Google\Service\Calendar.php'.
I also search information for my problem, I see that: http://stackoverflow.com/questions/8257678/google-calendar-api-v3-hardco...
Could you confirm that the access token is not mandatory to read private calendar ??
(https://developers.google.com/accounts/docs/OAuth2ForDevices)
Comment #28
johnlclark commentedI'm using 7.x-1.0-beta1 and still have a few issues. First, multiple calendars in a block throw:
Warning: Invalid argument supplied for foreach() in template_events() (line 710 of ../sites/all/modules/gcal_events/gcal_events.module).
Second, the URL(s) no longer work. #URL# won't properly be replaced because I wasn't sure where to fetch it from the API.
By looking at the API, I found this: "htmlLink" returns the URL
Having the URL is an important part of this module.
Comment #29
glidetothehoop commentedHelp! Do I have to request a "server key" or can I request a "browser key" from the Google Developer Console?
The "server key" option asks me for server IP addresses. How do I know what those are?
I'm using a web hosting service (DreamHost) not my own server.
Thanks,
Greg
Comment #30
djkouza commentedWe have started getting the
GCal Events: Bad call to list eventserror again starting yesterday sometime yesterday or Tuesday 12/2Drupal 6--
Comment #31
seplwebmaster commentedI just downloaded the module and came to find that I couldn't specify multiple calendar IDs.
I have modified the 'gcal_events.module' file to enable multiple calendar IDs once again. If anyone is interested, here it is "AS IS". I don't know how to create patches for Drupal, nor am I interested in learning. I just want to share my quick fix in case others want to use it. If someone wants to take it and compare it to the original module file to create a patch, that'd be great, provided my quick fix is acceptable.
In short, variables were changed at lines 595 and 601 (added an "s" to the calendar ID variable) and a for loop was added at lines 646 to 710. The return variable was changed at line 709.
YMMV
Comment #32
Michael Hodge Jr commentedPutting this back to needs work until a patch is created
Comment #33
seplwebmaster commentedI realized that my quick fix broke the order the dates are in (or maybe it was already broke). I've fixed that. I have also fixed the "#URL#" replacement as I had a need for it. I also noticed that the "today only" code appeared to be wrong and therefore was showing not only today's events, but also tomorrow's events when near the end of the day. I've changed it to my liking and now only today's events show.
New file attached. Again, provided "AS IS" and YYMV.
Comment #34
djkouza commentedFYI Found a fix to my problem... had to download an updated google-api-php-client !!!
Comment #35
nderendinger commentedApplied patch but didn't apply totally clean. Hand did rest. Thought I had it right but php error log shows this error:
[10-Dec-2014 14:27:51 America/Chicago] PHP Notice: Undefined offset: 8192 in /nfs/c04/h06/mnt/60127/domains/xxxxxx.org/html/modules/gcal_events/simplepie.inc on line 3473
There is no more simplepie references in my .module.
Any ideas where to look?
Comment #36
JL2014 commentedHi,
Today, I use another product for many reasons but I can say you that I have see for PRIVATES calendars:
- I use a .p12 key file generated in the console.developers.google.com (OAuth account service if I remember correctly)
- I use this key in php script that also use the library google-api-php-client (v3)
- Important: I have modified the rights in the properties of the google private agenda to authorize the system account linked with the p12 file ie the "system account" .apps.googleusercontent.com to have readonly rights on the calendar.
Then, I don't have error "not found" or other on these privates calendars with "calendars v3" url (not the old "feeds" url).
Hope that help, sorry for bad english.
Jean-Louis (from France)
Source code:
define('CLIENT_ID', '********.apps.googleusercontent.com');
define('SERVICE_ACCOUNT_NAME', '********@developer.gserviceaccount.com'); // this account must have readonly rights on private calendar settings
define('KEY_FILE', dirname(__FILE__) . '/My_project-123456789012.p12');
// !!! DON'T FORGET TO DENY ACCESS (via htaccess for example) TO THE .P12 PRIVATE FILE !!!
require dirname(__FILE__) . '/libraries/google-api-php-client/src/Google/Client.php';
require dirname(__FILE__) . '/libraries/google-api-php-client/src/Google/Service/Calendar.php';
$client = new Google_Client();
$client->setApplicationName("Calendar");
$key = file_get_contents(KEY_FILE);
$credentials = new Google_Auth_AssertionCredentials(SERVICE_ACCOUNT_NAME, array('https://www.googleapis.com/auth/calendar'), $key);
$client->setAssertionCredentials($credentials);
if($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($credentials);
}
// ...
$service = new Google_Service_Calendar($client);
// ...
$events = $service->events->listEvents($calendarID, $eventOptions);
// ...
Comment #37
retsiemppil commentedThank you seplwebmaster for the patch from #33. From my testing, this works great with multiple calendars except sorting events from multiple months. In that case, an event happening on March 4 would display before an event on Feb. 5. To fix this, I found you could change line 711 as follows:
old: $multiple_cal_events_sort[$key] = $row['date']; //sort by date key
new: $multiple_cal_events_sort[$key] = $row['timestamp']; //sort by timestamp
Again, thanks for the fix.
Comment #38
seplwebmaster commentedYes, I just picked this back up and ran into the same problem today. Your solution was simpler than mine. Thank you.
I don't think it really matters but, you may want to change the 'SORT_NATURAL' parameter to 'SORT_NUMERIC' on the line after if you haven't already.
I have made many more edits since my last post and feel I've customized this module too much to keep posting here so this will be my last post. Mainly my edits are to theme it and color coordinate calendar events, not functionality per se.
However, a bug in the module is a missing line of code that will affect saving the 'Endtime Template (#ENDTIME#)' field. To fix it, simply add the following on or around line 529:
variable_set('gcal_events_template_endtime_' . $delta, $edit['gcal_events_template_endtime']);Similarly, to fix resetting the block, add this around line 574:
variable_del('gcal_events_template_endtime_' . $block_number);Glad someone found it useful though.
Comment #39
E Johnson commentedIs this module working for anyone with API v3?
Any ideas? Thanks.
*EDIT*
Comment #40
brggmn commentedI am quite new to drupal and am wondering how to apply this patch. I got the calender working before, but now it fails.
I have my website hosted on a server which is not mine, and have only a directadmin panel available to administer this site.
Somebody an idea?
Thanks in advance!
Comment #41
peeyurr commentedIm in the same boat. I copied/pasted the gcal_events.module.txt to the file (online text editor). I also put in the developer ID and uploaded the google calendar plugin library.
Not sure what Im doing wrong, but I dont see the blocks on the website. Any ideas? Thanks in advance.
Comment #42
jdwfly commentedPlease file separate bug reports for other issues. I am using the latest dev in production.