How do I insert into non-default Google Calendar using Zend / PHP - php

I'm trying to insert a new event into Google Calendar, which I can do fine by the following:
$sname = Zend_Gdata_Calendar::AUTH_SERVICE_NAME; // predefined service name for calendar
$client = Zend_Gdata_ClientLogin::getHttpClient($userName,$password,$sname);
$service = new Zend_Gdata_Calendar($client);
$event = $service->newEventEntry();
$event->title = $service->newTitle($name);
$event->when = array($when);
$newEvent = $service->insertEvent($event);
However, this will only insert into the default calendar. I am trying to use the URI argument of insertEvent to get where I need to go:
$uri = "http://www.google.com/calendar/feeds/default/something#somethingelse.com/private/full";
$newEvent = $service->insertEvent($event, $uri);
This hasn't worked. I've tried encoding and decoding the URI, which gives me different error messages, but I just can't get this to work. I've been Googling solutions for hours now with no luck. Can anyone help?
Thanks.
- Dave

Found the issue:
The URI above doesn't work:
"http://www.google.com/calendar/feeds/default/something#somethingelse.com/private/full";
should not have the default section there.
Also, the # sign should be replaced by encoding. So it should be:
"http://www.google.com/calendar/feeds/something%40somethingelse.com/private/full";

I have been fighting this for awhile and I finally got it to work. This is not wrapped nicely, but this is the answer I was looking for
First you have to get the calendar ID. If you go into your calendar and click on the down arrow icon next to the name you will see an option for Calendar Settings. Select that menu item. Near the bottom you will see Calendar Address. It will take a moment to find the Calendar ID and it will look something like this
(Calendar ID: o4g3921hdiaq5p8kdat2l4vgis#group.calendar.google.com)
You want o4g39j1hdihq4p8kdat2l4vgis#group.calendar.google.com
Down the road I will want to get this in php but for now I can hard code. So I set a variable to this
$calendar_user = 'o4g39j1hdihq4p8kdat2l4vgis#group.calendar.google.com';
When retrieving events you will setUser like this
$gdataCal = new Zend_Gdata_Calendar($client);
$query = $gdataCal->newEventQuery();
$query->setUser($calendar_user);
But when you are adding event you can't do that you have to use the $calendar_user at the point where you insert the event.
So here is the complete code
$calendar_user = 'o4g39j1hdihq4p8kdat2l4vgis#group.calendar.google.com';
$user = 'myemail#yahoo.com';
$pass = 'mygooglecalendarpassword';
$service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME; // predefined service name for calendar
$client = Zend_Gdata_ClientLogin::getHttpClient($user,$pass,$service);
$gc = new Zend_Gdata_Calendar($client);
$newEntry = $gc->newEventEntry();
$newEntry->title = $gc->newTitle("mytitle");
$newEntry->where = array($gc->newWhere("meeting place"));
$newEntry->content = $gc->newContent("Meeting description");
$newEntry->content->type = 'text';
$when = $gc->newWhen();
$when->startTime = "{'2012-06-28'}T{'10:00'}:00.000{'-08'}:00";
$when->endTime = "{'2012-06-28'}T{'11:00'}:00.000{'-08'}:00";
$newEntry->when = array($when);
$createdEvent = $gc->insertEvent($newEntry, "http://www.google.com/calendar/feeds/".$calendar_user."/private/full");
Now I hope that is helpful. I tell you it took me way too long to figure this out, but I am not the smartest guy in the world.

Related

Netsuite Suitetalk API and PHP Toolkit - Customer Search with Two Filters

I'm trying to search with NetSuite SuiteTalk API using the PHP Toolkit.
The search works if I only use one filter - email, but returns an error when I add the subsidiary filter (the parts that are commented out).
<?php
require_once '..\PHPToolkit\NetSuiteService.php';
$netsuiteService = new NetSuiteService();
$emailSearch = new SearchStringField();
$emailSearch->operator = "is";
$emailSearch->searchValue = "testing#gmail.com";
//$subsidiarySearch = new SearchEnumMultiSelectField();
//$subsidiarySearch->searchValue = [1];
//$subsidiarySearch->operator = 'anyOf';
$search = new CustomerSearchBasic();
$search->email = $emailSearch;
//$search->subsidiary =$subsidiarySearch;
$searchRequest = new searchRequest();
$searchRequest->searchRecord =$search;
$searchResponse = $netsuiteService->search($searchRequest);
?>
Subsidiary is not an enum. Use SearchMultiSelect.
The search value will be a RecordRef.
Create the RecordRef first, then assign it to the searchValue of the multiSelect.

TransactionSearchBasic() amountPaid & amountRemaining Null

When i use the following php code with the 2016 Netsuite toolkit to retrieve an invoice, the returned object has the properties amountPaid & amountRemaining but they are both Null. Why are they not showing the values they should be, why include them if only always empty, and whats the best way around this ?
$search = new TransactionSearchBasic();
$SearchLongField = new SearchLongField();
$SearchLongField->searchValue = $internalId;
$SearchLongField->operator = "equalTo";
$search->internalIdNumber = $SearchLongField;
$_csearch = new RecordRef();
$_csearch->type = 'customer';
$_csearch->internalId = $customerId;
$custSearchField = new SearchMultiSelectField();
$custSearchField->searchValue[] = $_csearch;
$custSearchField->operator = "anyOf";
$search->entity = $custSearchField;
$request = new SearchRequest();
$request->searchRecord = $search;
$searchResponse = $this->service->search($request);
$result = json_decode(json_encode($searchResponse), true);
// Return results
return $result;
So though I have not received any outside responses yet, after further research and experimentation Ive come tho the belief that NS will return a full object structure for each data type whether all the properties (keys) are set or not.
And in the case of TransactionSearchBasic and other SearchBasic extensions it only returns a 'basic' subset of common fields used, the others just have Null as their value.
To get these extra data fields populated you have to request them with TransactionSearchAdvanced, and either a saved search or using the columns field. The flip side of this is as far as i can tell, you have to specify all columns you want, there's no way to just add a few extra fields to a Basic search.
NS API documentation is almost non-existent, but i work off this:
http://www.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2016_2/schema/search/transactionsearchadvanced.html?mode=package
and recently found this:
https://usergroup.netsuite.com/users/

Get facebook posts for specific date

I have something like this :
$config = array();
$config['appId'] = '';
$config['secret'] = '';
$config['fileUpload'] = false; // optional
$facebook = new Facebook($config);
$pageid = "";
// now we can access various parts of the graph, starting with the feed
$pagefeed = $facebook->api("/" . $pageid . "/feed");
i want to get all posts for specific date but i don't know how to do this. If someone can help me it will be great.
You can use time-based pagination. You can read more here (Read Time-based pagination). There is a nice How-To paging with graph API and FQL which can be used for reference.
Here is a simple call that pages through posts on the Chick-fil-A Page:
https://graph.facebook.com/chickfila/posts?limit=5&since={since}&until={until}access_token={access_token}
where
{since} is a Unix timestamp or strtotime data value that points to the start of the range of time-based data.
{until} is a Unix timestamp or strtotime data value that points to the end of the range of time-based data.
{access_token} is users access token.

eBay API - FindItemsAdvanced call in PHP does not return any response

Im trying to perform a simple call using ebays search API, when I make a call I get no response, and the problem is with the actual call itself.
$endpoint = 'http://open.api.ebay.com/shopping?';
$responseEncoding = 'XML';
$version = '631'; // API version number
$appID = 'asdf3e6e3';
$itemType = "AllItemTypes";
$itemSort = "EndTime";
//find items advanced
$apicalla = "$endpoint"
."callname=FindItemsAdvanced"
."&version=$version"
."&siteid=0"
."&appid=$appID"
."&MaxEntries=10"
."&ItemSort=EndTime"
."&ItemType=AllItemTypes"
."&IncludeSelector=SearchDetails"
."&responseencoding=$responseEncoding";
$resp = simplexml_load_file($apicalla);
this call is the equivalent to
http://open.api.ebay.com/shopping?callname=FindItemsAdvanced&version=631&siteid=0&appid=asdf3e6e3&MaxEntries=10&ItemSort=EndTime&ItemType=AllItemTypes&IncludeSelector=SearchDetails&responseencoding=XML
My question is what am I missing to make this simple search call?
It looks like you're trying to use eBay's Shopping API, specifically the FindItemsAdvanced call which I believe was deprecated quite some time ago and may no longer be functional (I no longer see it in the call reference). What you want to do is use use findItemsAdvanced from eBay's Finding API.
First, you'll need to change your API endpoint & query string parameters a bit (see the aforementioned findItemsAdvanced call reference for the specifics, but I believe it'll look more like this (I haven't touched my findItemsAdvanced calls in at least 6 months, so I haven't tested this):
$endpoint = 'http://svcs.ebay.com/services/search/FindingService/v1?';
$responseEncoding = 'XML';
$version = '1.8.0'; // API version number (they're actually up to 1.11.0 at this point
$appID = 'asdf3e6e3';
$itemSort = "EndTimeSoonest";
//find items advanced
$apicalla = "$endpoint"
."OPERATION-NAME=findItemsAdvanced"
."&SERVICE-VERSION=$version"
."&GLOBAL-ID=EBAY-US"
."&SECURITY-APPNAME=$appID"
//."&MaxEntries=10" // look for an equivalent for this (maybe paginationInput.entriesPerPage?)
."&sortOrder=EndTimeSoonest"
//."&ItemType=AllItemTypes" // not needed AFAICT, otherwise look at itemFilterType
."&descriptionSearch=true";
."& RESPONSE-DATA-FORMAT=$responseEncoding";
$resp = simplexml_load_file($apicalla);
In addition to this, to use findItemsAdvanced, you must specify what you're searching for either by category (categoryId) or by keywords (keywords), hence the "Please specify a query!" error message.
So, you also need to add something like the following (assuming keywords):
$keywords = "something";
$apicalla .= "&keywords=" . urlencode($keywords);
Giving you the following:
$endpoint = 'http://svcs.ebay.com/services/search/FindingService/v1?';
$responseEncoding = 'XML';
$version = '1.8.0'; // API version number (they're actually up to 1.11.0 at this point
$appID = 'asdf3e6e3';
$itemSort = "EndTimeSoonest";
$keywords = "something"; // make sure this is a valid keyword or keywords
//find items advanced
$apicalla = "$endpoint"
."OPERATION-NAME=findItemsAdvanced"
."&SERVICE-VERSION=$version"
."&GLOBAL-ID=EBAY-US"
."&SECURITY-APPNAME=$appID"
//."&MaxEntries=10" // look for an equivalent for this (maybe paginationInput.entriesPerPage?)
."&sortOrder=$itemSort"
//."&ItemType=AllItemTypes" // not needed AFAICT, otherwise look at itemFilterType
."&descriptionSearch=true";
."& RESPONSE-DATA-FORMAT=$responseEncoding"
."&keywords=" . urlencode($keywords);
$resp = simplexml_load_file($apicalla);
One final note: If you want to load further details of specific items that you find in your results, you'll still want to use the Shopping API (specifically the GetSingleItem & GetMultipleItems calls). So, you may ultimately use a mix of the Shopping & Finding APIs.
It should be something like:
<?php
$url = 'http://svcs.ebay.com/services/search/FindingService/v1?OPERATION-NAME=findItemsAdvanced&SERVICE-VERSION=1.11.0&SECURITY-APPNAME=YOUR_APP_ID&RESPONSE-DATA-FORMAT=XML&REST-PAYLOAD&paginationInput.entriesPerPage=2&keywords=ipod&siteid=203&GLOBAL-ID=EBAY-IN';
$xml = file_get_contents( $url );
$xml = simplexml_load_string( $url );
?>
Log-in to your ebay developer account and click on this link: Test your calls with API Test Tool
Hope this helps.

Using LocationSearchParameter for TargetingIdeaService v201109

I am trying to use LocationSearchParameter with TargetingIdeaService (v201109). I am struggling with an Invalid_Criterion_ID error. May I request some help with that? Here is how I am setting LocationSearchParameter in php
$locationTargetParameter = new LocationSearchParameter();
$locationTargetParameter->locations=$LocArray; // $LocArray is array of IDs 2840 for US
As of v201702. Here's a working example.
$loc = array();
$location = new location();
$location->setId(2840); // USA
$loc[]=$location;
$locationTargetParameter = new LocationSearchParameter();
$locationTargetParameter->setLocations($loc);
$searchParameters[] = $locationTargetParameter;
Also if you're copying the example file found here. Don't forget to include
use Google\AdsApi\AdWords\v201702\o\LocationSearchParameter;
Since this is needed for the LocationSearchParameter to work.
As for documentation and location IDs, check here.
Here is what worked for me in case there are others looking to do the same thing:
$loc = array();
$location = new location();
$location->id = '2840';
$loc[]=$location;
$locationTargetParameter = new LocationSearchParameter();
$locationTargetParameter->locations=$loc;

Categories