Google has chanced some things with their calendar API, and now I need to fix some strange symbols that are adding themselves to text. I found this thread which exactly describes the issue I'm dealing with:
http://www.google.com/support/forum/p/Calendar/thread?tid=25ac3d762b235a51&hl=en
The solution is to append "&hl=en" or "?hl=en" to the end of my 'basic' URL feed.
I'm confunsed how to do that though, because I am retrieving the feed as an object with Zend_Gdata:
<?php
// load library
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Calendar');
Zend_Loader::loadClass('Zend_Http_Client');
// create authenticated HTTP client for Calendar service
$gcal = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
$user = "xxxxx";
$pass = "xxxxx";
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $gcal);
$gcal = new Zend_Gdata_Calendar($client);
$query = $gcal->newEventQuery();
$query->setUser('xxxxx#group.calendar.google.com');
$secondary=true;
$query->setVisibility('private');
$query->setProjection('basic');
$query->setOrderby('starttime');
$query->setSortOrder('ascending');
//$query->setFutureevents('true');
$startDate=date('Y-m-d h:i:s');
$endDate="2015-12-31";
$query->setStartMin($startDate);
$query->setStartMax($endDate);
$query->setMaxResults(30);
try {
$feed = $gcal->getCalendarEventFeed($query);
} catch (Zend_Gdata_App_Exception $e) {
echo "Error: " . $e->getResponse();
}
?>
I tried to do this with no luck:
$query->setProjection('basic?hl=en');
Note: I've not used any of this before so I apologize if this doesn't work :)
The documentation says that getCalendarEventFeed() can take a URL as the parameter.
So we can change this...
$feed = $gcal->getCalendarEventFeed($query);
... to this in order to add the parameter to the query string:
$eventUrl = $query->getQueryUrl() . '?hl=en';
$feed = $gcal->getCalendarEventFeed($eventUrl);
Obviously, this is a simplified example - you should still perform the following two checks:
Make sure $query is an instance of Zend_Gdata_Query before calling getQueryUrl() on it.
Ensure that there are no other query parameters already added to $eventUrl so that we can use &hl=en rather than ?hl=en. You could probably use Zend_Uri for this.
Related
We have a case where we need to check envelope status in two separate Docusign accounts. If we don't get status in the first, we want to check the second.
I'm having trouble getting the API to re-initialize with the credentials of our second account. I'm calling this snippet with the new variables:
require_once('docusign/SignatureApi.php');
$IntegratorsKey = "abcd";
$UserID = "dave#account.com";
$Password = "xxxxx";
$_apiEndpoint = $Endpoint;
$_apiWsdl = "docusign/api/APIService.wsdl";
$api_options = array('location'=>$_apiEndpoint,'trace'=>true,'features' => SOAP_SINGLE_ELEMENT_ARRAYS);
$api = new APIService($_apiWsdl, $api_options);
$api->setCredentials("[" . $IntegratorsKey . "]" . $UserID, $Password);
$res = RequestEnvelopStatuses($envelopes);
$envelopeStatuses = $res->RequestStatusesResult;
if(!count($envelopeStatuses->EnvelopeStatuses->EnvelopeStatus)){
// If we did not find envelopes, check other account
$IntegratorsKey = "wxyz";
$UserID = "fred#altaccount.com";
$Password = "xxxxx";
$api->setCredentials("[" . $IntegratorsKey . "]" . $UserID, $Password);
// retry request
$res = RequestEnvelopStatuses($envelopes);
$envelopeStatuses = $res->RequestStatusesResult;
}
It doesn't return an error, but won't return envelope status either. It seems to still use the first credentials (guessing). The second attempt always seems to return whatever the first attempt did.
Is there a better / preferred way to do this?
That does not look like the proper way to get the envelope status. Maybe that's why you are not finding them and trying to look again?
// Create a filter using account ID and today as a start time
$envStatusFilter = new EnvelopeStatusFilter();
$envStatusFilter->AccountId = $AccountID;
$beginDateTime = new EnvelopeStatusFilterBeginDateTime();
$beginDateTime->_ = todayXsdDate(); // note that this helper function
// is in CodeSnippets/include/utils.php
// in the PHP SDK
$envStatusFilter->BeginDateTime = $beginDateTime;
// Send
$requestStatusesparams = new RequestStatuses();
$requestStatusesparams->EnvelopeStatusFilter = $envStatusFilter;
$response = $api->RequestStatuses($requestStatusesparams);
I've got my session with the valid token that i set up this way :
$session_token = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']);
// Store the session token in our session.
$_SESSION['cal_token'] = $session_token;
Then i want to be able to do this:
$service = Zend_Gdata_Docs::AUTH_SERVICE_NAME;
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
$docs = new Zend_Gdata_Docs($client);
$feed = $docs->getDocumentListFeed();
But using the token. Instead of the authentication with user/pass/service
I already looked at some example of this but i didn't find any way to make it work.
Thank you everyone!
// Retrieve user's list of Google Docs
$client = Zend_Gdata_AuthSub::getHttpClient($_SESSION['cal_token']);
$docs = new Zend_Gdata_Docs($client);
$feed = $docs->getDocumentListFeed();
foreach ($feed->entries as $entry) {
echo "$entry->title\n";
}
Using the latest PHP CLient Library (v2.6.3) I can't seem to figure out to get all campaigns for a client in my MCC (my client center) account.
I can easily get all accounts via:
$user = new AdWordsUser(NULL, $email, $password, $devToken, $applicationToken, $userAgent, NULL, $settingsFile);
$service = $user->GetServicedAccountService();
$selector = new ServicedAccountSelector();
$selector->enablePaging = false;
$graph = $service->get($selector);
$accounts = $graph->accounts; // all accounts!
Now that I've done that, I want to get all the campaigns within each account. Running the code as documented here doesn't work.
// Get the CampaignService.
// ** Different than example because example calls a private method ** //
$campaignService = $user->GetCampaignService('v201101');
// Create selector.
$selector = new Selector();
$selector->fields = array('Id', 'Name');
$selector->ordering = array(new OrderBy('Name', 'ASCENDING'));
// Get all campaigns.
$page = $campaignService->get($selector);
// Display campaigns.
if (isset($page->entries)) {
foreach ($page->entries as $campaign) {
print 'Campaign with name "' . $campaign->name . '" and id "'
. $campaign->id . "\" was found.\n";
}
}
All the above code will do is throw an error:
Fatal error: Uncaught SoapFault exception: [soap:Server]
QuotaCheckError.INVALID_TOKEN_HEADER # message=null
stack=com.google.ads.api.authserver.common.AuthException at
com.go;
I have a feeling that the reason this fails is that GetCampaignService needs an account's id...but I can't figure out how to specify this id.
What am I doing wrong?
The problem ended up being that I was given the wrong developerToken. I didn't think INVALID_TOKEN_HEADER really meant what it said because SOME calls still worked with the faulty token. I don't know why.
I was following a tutorial on using the Google Calendar API with the ZEND Framework(http://maestric.com/doc/php/google_calendar_api). I am able to retrieve events from my default calendar by setting the calendar ID: $query->setUser('IDGoesHere');. The problem is I'm not sure how to grab events from all of the calendars I am subscribed to. Is there a way to achieve this or is it not even possible?
Any help is appreciated.
Here is the PHP:
$path = 'ZendGdata/library';
$oldPath = set_include_path(get_include_path() . PATH_SEPARATOR . $path);
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Calendar');
$user = 'username';
$pass = 'password';
$service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
try
{
$client = Zend_Gdata_ClientLogin::getHttpClient($user,$pass,$service);
}
catch(Exception $e)
{
echo "Could not connect to calendar.";
die();
}
$gdataCal = new Zend_Gdata_Calendar($client);
$query = $gdataCal->newEventQuery();
$query->setUser('usernameHere');
$query->setVisibility('private');
$query->setSingleEvents(true);
$query->setProjection('full');
$query->setOrderby('starttime');
$query->setSortOrder('ascending');
$query->setMaxResults(20);
$event_list = $gdataCal->getCalendarEventFeed($query);
Grab the events and display them:
foreach ($event_list as $event)
{
echo $event->title ';
echo $event->where[0];
echo $event->content ;
}
You need to setUser to the user id of the secondary calendar.
I'm using the BLogger API (google) to try and search for certain strings (i.e.'John Doe is my friend' - and return the blog id/url/etc) on public blogs. All I have found until now returns only data for my own account, not all public accounts.
Here's what I have now, it doesn't output much as I have no blogs set up myself. I've tried adding parameters and such to narrow down the search, but I feel the $query will need to change a bit.
<?php
$user = 'xxxxxx';
$pass = 'xxxxxx';
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_Query');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Feed');
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, 'blogger', null,
Zend_Gdata_ClientLogin::DEFAULT_SOURCE, null, null,
Zend_Gdata_ClientLogin::CLIENTLOGIN_URI, 'GOOGLE');
$gdClient = new Zend_Gdata($client);
function printAllBlogs(){
$query = new Zend_Gdata_Query('http://www.blogger.com/feeds/default/blogs');
$feed = $gdClient->getFeed($query);
printFeed($feed);
}
function printFeed($feed){
$i = 0;
foreach($feed->entries as $entry) {
print $i ." ". $entry->title->text . "\n";
$i++;
}
}
?>
I figure this shouldn't be too crazy...just haven't found a solution yet. Thanks!
You say you're using the Blogger API, but for searching blogs you should use the Blog Search API, i think.
EDIT: It's only for Javascript, apparently...