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.)
Related
So I'm creating an application that allows users to record a message through Twilio and I'm attempting to store the RecordingSID, the date it was created, and the duration of the recording in a MySQLi database right after the recording has been made. I've managed to get the RecordingSID by taking the last 34 digits off the RecordingURL using the substr() function and am simply getting whatever today's date is for the date created field in my database table. However, seemingly regardless of how long the actual recording is, I'm continually getting a value of 8 when attempting to get the recording duration. Here's what I've got right now (with database inserts omitted since they work):
<?php
$recordingURL = $_REQUEST['RecordingUrl'];
$recordingSID = substr($recordingURL, -34);
date_default_timezone_set('EST');
$dateCreated = date("Y-m-d");
$duration = $_REQUEST['RecordingDuration'];
?>
Any help with this matter would be fantastic! Thanks!
Edit: I've also tried the following solution in place of the last line in my previous code snippet:
<?php
$recordings = $client->account->recordings->getIterator(0, 50, array('Sid' => $recordingSID,));
foreach ($recordings as $recording)
{
$duration = $recording->duration;
}
?>
Based on that code sample you've pasted in, you could be doing a couple of things incorrectly. Correct me if I'm wrong, but I believe you are trying to request a Recording resource back from the Twilio API after you've submitted one with the Twilio js and their TwiML?
If so, twilio actually has a nice little demo of exactly your use case.
You shouldn't see anything in the $_REQUEST['RecordingDuration'], I'm not sure why you are even getting a value of 8 returned. Basically what you want to do is find the users recordings by using the Twilio REST API.
here is an example snippet:
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library
// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACda6f132a3c49700934481addd5ce1659";
$token = "{{ auth_token }}";
$client = new Services_Twilio($sid, $token);
// Loop over the list of recordings and echo a property for each one
foreach ($client->account->recordings as $recording) {
echo $recording->duration;
}
The response from the API call will return a Recording resource.
Here is some more examples from their docs
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 :)
I have a custom report called my-newsletters in Google analytics. I want to fetch this report with a php call to $ga->requestReportData(...) and then parse the response and format it up.
First I made an account to collect all my newsletter open and click hits - each time someone opens a newsletter or clicks on a link in the newsletter I capture that with a call to the __utm.gif on Google. That part is working and I include in the call ( in the Landing Page aka utmp parameter) some data such as the word 'open' and 'click' to distinguish the events and also some other data i hope to parse out later, plus i use the campaign field and maybe I should do something with the source field too - now I just dup the utmp field. So far that part seems to work.
Now I need help to define a report that will return that utmp and campaign field info and the number of hits each has taken, sorted by date of hit I guess. then i need to call that report from my php and then later parse it - the parsing part I'm not worried about yet.
PS: here is the code I use to generate the utm url
function getGoogleUtmUrl($source='Emails', $referer='opens', $estid='0',$mailid='0', $campaign){
$stat_id='MO-xxx31982-1';
$var_utmcs=urlencode( 'UTF-8');
$var_utmac = $stat_id;
$var_utmhn = 'mysite.com'; //enter your domain
$var_utmn = rand(1000000000,9999999999); //random request number
$var_cookie = rand(10000000,99999999); //random cookie number
$var_random = rand(1000000000,2147483647); //number under 2147483647
$var_today = time(); //today
$var_referer = $referer; //referer url
$utm_source = 'my_newsletter';
$utm_medium = 'Emails';
$utm_campaign = $campaign;//$_GET['url'];
$var_uservar = $estid.'_'.$mailid; //enter your own user defined variable
$var_utmp = 'mysite.com/newsletters/'.$referer.'/'.$estid.'/'.$mailid;//.$estid;//$_GET['url']; //this example adds a fake file request to the (fake) tracker directory (the image/pdf filename).
$urchinUrl1 = 'http://www.google-analytics.com/__utm.gif?utmwv=4.3&utmn='.$var_utmn.'&utmsr='.$referer.'&utmcs='.$var_utmcs.
'&utmul=en&utmje=0&utmfl=-&utmdt='.$utm_campaign.'&utmhn='.$var_utmhn.
'&utm_source='.$var_utmp.'&utm_medium='.$utm_medium.'&utm_campaign='.$utm_campaign.'&utmr='.$var_referer.
'&utmp='.$var_utmp.'&utmac='.$var_utmac.
'&utmcc=__utma%3D'.$var_cookie.'.'.$var_random.'.'.
$var_today.'.'.$var_today.'.'.$var_today.
'.2%3B%2B__utmb%3D'.$var_cookie.'%3B%2B__utmc%3D'.
$var_cookie.'%3B%2B__utmz%3D'.$var_cookie.'.'.$var_today.
'.2.2.utmccn%3D(direct)%7Cutmcsr%3D(direct)%7Cutmcmd%3D(none)%3B%2B__utmv%3D'.
$var_cookie.'.'.'%3B';
// Now fire off the HTTP request
echo "urchinURL1 == ".$urchinUrl1.' '.__FILE__.' '.__LINE__.'<br/>';
return $urchinUrl1;
seems like over kill to me but it works, I tried the code at https://developers.google.com/analytics/devguides/collection/other/mobileWebsites and it doesn't work - the opens and clicks do not register in analytics - at least not on the real time page.
Please help.
I suggest that you build your report query first, I recommend that you use Google Analytics Query Explorer for that.
And next use the reporting API from PHP to transpose the resulting query and extract the data from within your app.
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.
How Can I find whether the transaction made by user is settled or Unsettled in the authorize.net.I am using AIM.
I want to get through coding.When the transaction is completed and I cant find transaction status.But I want to get whether it goes for settled or unsettled transaction.
Thanks in advance.
You cannot get this information through coding as no API Authorize.Net offers allows for this. It can only be done through the control panel. When you process a transaction and it is approved you can assume the transaction is unsettled. Transactions are settled once per day usually around midnight Pacific Time. After that you can assume a transaction is settled.
As of 03-16-2011 authorize.net has released two new calls to the Transaction Details API, getUnsettledTransactionList and getBatchStatistics.
getUnsettledTransactionList returns up to 1,000 unsettled transactions per call, returning the most recent transactions. The information returned in the response will be the same as what's returned in getTransactionList call.
getBatchStatistics returns the batch stats for a single batch like settlement state and time, charge count, decline count, etc.
For more info, check out the XML guide and the SOAP guide.
At the time of writing the PHP SDK is at version 1.1.6 and does not have this function built into the TD api, however if you look at the documentation provided above, as well as this example page, you will see that getting a list of unsettled transactions is in fact possible.
from this page
I've followed this link http://developer.authorize.net/api/transaction_details/ and get this code from there,
<?php
require_once "anet_php_sdk/AuthorizeNet.php";
define("AUTHORIZENET_API_LOGIN_ID", "YOURLOGIN");
define("AUTHORIZENET_TRANSACTION_KEY", "YOURKEY");
// Get Settled Batch List
$request = new AuthorizeNetTD;
$response = $request->getSettledBatchList();
echo count($response->xml->batchList->batch) . " batches\n";
foreach ($response->xml->batchList->batch as $batch) {
echo "Batch ID: " . $batch->batchId . "\n";
}
// Get Transaction Details
$transactionId = "12345";
$response = $request->getTransactionDetails($transactionId);
echo $response->xml->transaction->transactionStatus;
but I m getting this error message.
User authentication failed due to invalid authentication values.
As suggested in #cwd's answer, the most reliable way to know if a transaction is settled is to call getUnsettledTransactionList or getBatchStatistics, but you can also just check what your Transaction Cut-off Time is set to.
Log in to your Authorize.net admin, click Account > Transaction Cut-Off Time
My account is set to 4:00 PM PDT so you can just compare your transaction time to the cut off time. Something like:
$createdTime = new DateTime($charge['createdTime']);
// starting point for settle time
$settleTime = new DateTime($createdTime->format('Y-m-d') . ' 16:00:00');
$now = new DateTime();
// if card was charged after settle time for
// that day, move settle time to the next day
if ($createdTime > $settleTime) {
$settleTime->add(new DateInterval('P1D'));
}
if ($now > $settleTime) $settled = true;
http://developer.authorize.net/api/transaction_details/ is the API you are looking for.