I have been trying to play with Google calendar api v3. I have calendars and events listing no problem. However, I am trying to get certain data of events. I have getSummary() working and guessed getLocation().
Does anyone know how to call the start time for an event? Are these functions listed anywhere that I am missing?
if ($client->getAccessToken()) {
$calList = $cal->calendarList->listCalendarList();
//print "<h1>Calendar List</h1><pre>" . print_r($calList, true) . "</pre>";
$eventList = $cal->events->listEvents('yoyoyoyo#gmail.com');
foreach($eventList->getItems()as $eventList){
print "Name: ";
echo $eventList->getSummary();
echo "<br/><br/>";
print "Start: ";
echo $eventList->getdateTime(); <--- doesnt work hahah
echo "<br/><br/><hr>";
}
}
Why, yes. Pretty much every google API of all time comes with a useful grouping of related documentation. You can in fact usually simply google "google [name your api here] documentation" and be led straight to it. The google calendar's main page has a link straight to their docs, too.
That's all for future reference. For now, you can probably paruse this right here and find what you're looking for- because right there in the first section I do indeed see a JSON return for "start" and "end" times.
Good luck :)
Related
I'm using the Facebook Comments plugin (from FB, not a WP Plugin) on my WP site.
I want to get the number of comments for a specific URL, so I can set it up to say "start the conversation" or "join the conversation"
I've done my research and found several variations on the code below posted as recently as April of this year:
$rest_url = "http://api.facebook.com/restserver.php?format=json&method=links.getStats&urls=https://my.com/".$my_slug;
$json = json_decode(file_get_contents($rest_url), true);
// echo "Facebook Shares = " . #$json[0]['share_count'];
// echo "Facebook Likes = " . #$json[0]['like_count'];
echo "Facebook Comments = " . #$json[0]['comment_count'];
However, after some frustration, I realized I needed to dump $json and see what's in there:
var_dump($json);
and to just parse out the important part, there was a message inside:
"REST API is deprecated for versions v2.1 and higher (12)"
There's a lot I don't understand about APIs and Facebook's system.
But... can you tell me what the current way of getting the comment count is now? I just need it in a variable and I can go from there.
Thanks for any help!
Chris
I would be interested in some API theory. When I build up the REST Resources, who do you handle such things, like a search by the user for a resource without knowing details. Lets say I got the resource "taxi". So I could build up my API like this:
http://api.megataxi.com/v1/taxis
to get all taxis in my database. Lets say, the user's app will submit its current position with lat and lng, and I am searching for the nearest taxi around the user. What would be the best practice here? I would have gone for:
http://api.megataxi.com/v1/taxis/getTaxisInRange
So my routes file would have something like:
Route::post('/taxis/getTaxisInRange, 'TaxiCOntroller#getTaxisInRange');
but usually I would think the way to go would be done like:
http://api.megataxi.com/v1/taxis/list?lat=100&lng=100
But how would I reflect something like this in my routes?
To answer the second part of your question: how would I reflect something like this in my routes?
You could do something like this:
Route::get('taxis/lat/{lat}/lang/{lng}', function($lat, $lng) {
echo 'lat: '. $lat;
echo '<br>';
echo 'lng: '. $lng;
});
So you could hit the URL like: taxis/lat/100/lng/100
Or
Route::get('taxis', function() {
echo 'lat: '. \Input::get('lat');
echo '<br>';
echo 'lng: '. \Input::get('lng');
});
which would allow: taxis?lat=100&lng=100
If you're subscribed to laracasts.com you should check this out: https://laracasts.com/series/incremental-api-development
I asked the same question earlier and it got down voted and I have no idea why. I'm building a class that outputs a news feed, but it's a very structured html that I'm going to use a lot on the site (hundreds of times), so I'm using a class method to display the feed html and everything. And I just echo the whole thing.
The method is set up this way:
private function feed ($var)
{
$Statement = $this->Database->prepare("SELECT * FROM feed WHERE col = ? ORDER BY timestamp DESC LIMIT 50");
$Statement->execute(array($var));
while ($row = $Statement->fetch(PDO::FETCH_ASSOC))
{
echo ' <div class="feed-box">
' . /*facebook name retrieved from the facebook */ . '
' . $row["post"] . '
<br/>
</div>';
}
} //end feed
The class is set up so that another method that has more of the html template calls this feed method. (I'm not trying to be too redundant here, but again the last time I asked this question it got down voted). So I'm pretty new to oop, and I'm looking to display the profile pictures of people who are logged in with facebook. This isn't necessarily a facebook question because I know how to do it normally, but I don't know how to get the facebook information within the class scope using just their id. Normally I;d get their picture by going linking to this url https://graph.facebook.com//picture. How do I do this within the class when I only sotre their facebook id in the database? I've been working on this problem for a couple days now, and I can't figure it out on my own. So I really appreciate your help.
It's getting to the point where I just want to statically type everything out because I know I could easily do that, but I'd really love to learn what the proper way is, especially since editing so many of these little boxes if I want to change something one day would be a real hassle. Thanks for your help. I really appreciate it. Let me know if anything is unclear I'll update the questino as soon as I can.
How do I do this within the class when I only sotre their facebook id in the database
echo '<img src="https://graph.facebook.com/' . $row['facebook_id'] . '/picture" />' ;
You say you only store the facebook id in your database. That is all you need to display the picture. Just append /picture to the user's FB graph link to get the picture.
I am using the following code to parse XML data from a Google Calendar feed:
require_once('coreylib/coreylib.php');
$calendar = variable_get('calendar_id_setting');
$now = date('Y/m/d', strtotime('now'));
$next_week = date('Y/m/d', strtotime('+7 days'));
$api = new clApi('http://www.google.com/calendar/feeds/' . $calendar .'/public/full?singleevents=true&min-start=' . $now . '&max-start=' .$next_week);
if ($feed = $api->parse()) {
foreach($feed->get('entry') as $entry) {
error_log($title . ' ' . strtotime($entry->get('when#startTime')));
The problem is in the error log my first result is a unique event with correct title and time, but the following 25 results all have the same title and have a start time in 2026(?!).
All but one of the events are recurring events. I thought setting 'singleevents=true' on the URL would solve this problem but apparently not! What is the correct fix here?
Compare your URL with the one in the Calendar API v2 documentation. You're providing parameters min-start and max-start, in a format of 'Y/m/d'. The documentation shows an example with parameters of
start-min=2006-03-16T00:00:00&start-max=2006-03-24T23:59:59
Note the use of start-min and start-max, and a format of yyyy-MM-dd'T'HH:mm:ss. Given the parameter reference I suspect you could get away with just yyyy-MM-dd, but you should follow that format rather than using slashes and single-digit versions.
Of course that doesn't quite explain the results you're getting in 2026, but using the right parameters would be a good starting point.
Additionally, you may wish to consider using the v3 API and possibly the PHP (beta) client library.
(Note: although I work for Google and used to use the client API myself, this answer is provided purely in a personal capacity.)
there are plenty of tutorials on how to request and parse a list of events from Google Calendar using Zend GData.
But all tutorials assume that events never repeat. (Kind of, they describe how to set up repeating events, but not how to parse / display them.)
So I wrote a script to copy events from Google Calendar to a web site, but it just doesn't work because some of the events in the calendar are repeating and the method described in the tutorials results in pretty random output.
Any idea?
I think I've finally found the answer you're really looking for. Per http://code.google.com/apis/calendar/data/1.0/reference.html#Parameters, you need to set the 'singleevents' parameter to 'true', forcing the data returned to do it's own parsing and ordering of recurring events. So your code (based on http://code.google.com/apis/calendar/data/1.0/developers_guide_php.html#RetrievingDateRange) will look something like:
function outputCalendarByDateRange($client, $startDate='2007-05-01', $endDate='2007-08-01') {
$gdataCal = new Zend_Gdata_Calendar($client);
$query = $gdataCal->newEventQuery();
$query->setUser('default');
$query->setVisibility('private');
$query->setProjection('full');
$query->setOrderby('starttime');
$query->setStartMin($startDate);
$query->setStartMax($endDate);
$query->setsingleevents('true');
$eventFeed = $gdataCal->getCalendarEventFeed($query);
echo "<ul>\n";
foreach ($eventFeed as $event) {
echo "\t<li>" . $event->title->text . " (" . $event->id->text . ")\n";
echo "\t\t<ul>\n";
foreach ($event->when as $when) {
echo "\t\t\t<li>Starts: " . $when->startTime . "</li>\n";
}
echo "\t\t</ul>\n";
echo "\t</li>\n";
}
echo "</ul>\n";
}
The data that's returned from this function has a single event for each instance of your repeating events, ordered correctly among all the rest of the "normal" events. Exceptions to the recurrance rules (single event cancellations, for instance) are correctly reflected, as well.
So I think you can now use that method without any caveats or warnings...it should give you the data you want, in the way you want.
You can probably do it without the second "foreach" loop, since each event should only have one "when" now...replace lines 18-20 with
echo "\t\t\t<li>Starts: " . $event->when->startTime . "</li>\n";
But since Google's example does include that second foreach loop, it's probably safer to leave it in.
Hope it's not too late to help you!
-----Original answer:-----
(included just for the sake of completeness and because I'm still using this basic method to combine events from multiple calendars)
I'm working on this right now myself, using PHP to parse the feed and display some customized XML based on the data. The only solution I have come up with is to retrieve the dates/times of all the events, recurring or not, using:
$eventFeed = $gdataCal->getCalendarEventFeed($query);
foreach ($eventFeed as $event) {
foreach ($event->when as $when) {
$start=strtotime($when->startTime);
$end=strtotime($when->endTime);
}
}
Which works pretty well. The issue is that all the events will be returned "grouped" in order of the next occurances. That is, say it's Monday right now. If you've got a repeating event every Tuesday and another repeating event every Thursday, and you ask it for all events in the next 90 days, the list you'll get will first list every instance of the Tuesday event for the next 90 days, and THEN it will go on to list every instance of the Thursday event. For my purposes (and it sounds like, yours too), I wanted the list to be in order of the individual events coming up.
The only way I've found to do it, is to insert the data from each individual instance into a temporary SQL database table, including a column indicating the timestamp of the event's beginning. Then once it's all entered in the database, I can request that it give me back the events, ordered by the timestamp.
Thus my loop became something like:
mysql_query("CREATE TEMPORARY TABLE `temp` (`title` TEXT NOT NULL,`date` TEXT NOT NULL,`timestamp` TIMESTAMP NOT NULL)");
$eventFeed = $gdataCal->getCalendarEventFeed($query);
foreach ($eventFeed as $event) {
foreach ($event->when as $when) {
$start=strtotime($when->startTime);
$end=strtotime($when->endTime);
mysql_query("INSERT INTO `temp` (`title`,`date`,`timestamp`) VALUES ('".$event->title->text."','".date("M d h:i a",$start)."-".date("h:i",$end)."','".date("Y-m-d H:i:s",$start)."')");
}
}
$result=mysql_query("SELECT * FROM `mobile_app_events` ORDER BY `timestamp` ASC");
while($row=mysql_fetch_assoc($result)) {
echo "<item>\n";
echo "<title>".$row['title']."</title>\n";
echo "<date>".$row['date']."</date>\n";
echo "</item>\n";
}
Now, I'll caution you- the reason I've found this topic is because I'm looking for an answer myself...it seems that if the recurring events have any exceptions (for instance, next Thursday's event is cancelled), that doesn't get reflected in the output using these codes. Though next Thursday's event is deleted from your Google Calendar view, it still shows up on this page.
Other than that, (and assuming you've got access to a database), this seems to do the trick. I did add in a few lines to start a transaction before the process, with the theory that it might speed up the rendering of the data, not having to commit every insert.