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;
Related
I have an XML file which is something like this:
(fileName : abc.xml)
<Envelope>
<Body>
<SResponse>
<Body>
<SResponseDetails>
<SItem>...</SItem>
<SItem>...</SItem>
<SItem>...</SItem>
<SItem>...</SItem>
</SResponseDetails>
</Body>
</SResponse>
</Body>
</Envelope>
I want to store all <SItem> in a db table (1 record for each SItem). I am using PHP for it and using XmlStringStreamer.
Here is my code for reading this file and processing it.
$streamer = \Prewk\XmlStringStreamer::createStringWalkerParser(__DIR__ . "/tempFile.xml");
$stream = new Stream\File(__DIR__ . "/abc.xml", 1024);
$parser = new Parser\StringWalker();
$streamer = new XmlStringStreamer($parser, $stream);
while ($node = $streamer->getNode()) {
$simpleXmlNode = simplexml_load_string($node);
//-- code here for getting single node
}
I am using XmlStringStreamer and did not get any answer from any forum, I also tried but could not get what I want so, can anyone please help me.
Thanks Alot.
I have solved it, here is my answer for it.
For looping for specific item, we can directly use this in xmlStringSteamer:
$stream = new Stream\File(__DIR__ . "/abc.xml", 1024);
$options = array(
"uniqueNode" => "SItem"
);
$parser = new Parser\UniqueNode($options);
// Create the streamer
$streamer = new XmlStringStreamer($parser, $stream);
$countNodes = 0;
while ($node = $streamer->getNode())
{
print_r($node);
}
The only problem is that it converts xml tags to lowercase. like <SItem> becomes <sitem>. So, anyone have idea about this problem?
I didn't executed your code but i think you can use PHP logic. If anything doesn't work for you then last solution will be exploding $simpleXmlNode to get some array structure and then process it according to your need. By the way can you share what you got after $simpleXmlNode = simplexml_load_string($node)?
For others, i can't add comments so posting this as answer.
I have a XML file which was generated by an external entity that I want to parse using SimpleXML. My problem is that in the mapping given by the client I have some conditions in it to get the info I want.
For example, the mapping for the client code is something like this: E1ADRM1\PARTNER_Q=OSO\E1ADRE1\EXTEND_D which means that the code for the client is the value of the EXTEND_D tag, which is nested in one of the many PARTNER_Q tags. The one that has the OSO value.
I am starting today to explore SimpleXML, so I have no idea how to get this info.
For what I've read so far, it is pretty simple to get the info of a node, accessing it's properties. If I a single PARTNER_Q and no condition, my $clientCode would be $xml->E1ADRM1->PARTNER_Q->E1ADRE1->EXTEND_D (right?)
Any hint on how can I get the info having that PARTNER_Q=OSO condition in mind?
For future reference, I'll leave here the code with how I've solved this.
I've Based my code on this well written answer that I found.
$root = $xml->IDOC;
$shippingPoints = array();
// Go through the list of OTs
foreach($root->E1EDL20 as $ot) {
// Instanciate empty OT
$otInfo = emptyOt();
$otInfo["refOt"] = trim($ot->VBELN);
// Go through partner to get the wanted items
foreach ($ot->E1ADRM1 as $partner) {
switch ($partner->PARTNER_Q) {
case "OSO":
$otInfo["codeLoader1"] = trim($partner->E1ADRE1->EXTEND_D);
break;
case "OSP":
$otInfo["refShip"] = trim($partner->PARTNER_ID);
// get the shipping info if not already fetched
if(!isset($shippingPoints[$otInfo["refShip"]])) {
$shippingPoints[$otInfo["refShip"]] = Whouses::getWhouseAddressByCode($otInfo["refShip"]);
}
// assign values
$otInfo["brandNameShip"] = $shippingPoints[$otInfo["refShip"]]["name"];
$otInfo["addrShip1"] = $shippingPoints[$otInfo["refShip"]]["address"];
$otInfo["cityShip"] = $shippingPoints[$otInfo["refShip"]]["city"];
$otInfo["zipShip"] = $shippingPoints[$otInfo["refShip"]]["zipcode"];
$otInfo["countryShip"] = $shippingPoints[$otInfo["refShip"]]["country"];
break;
case "WE":
$otInfo["refDeliv"] = trim($partner->PARTNER_ID);
$otInfo["addrDeliv1"] = trim($partner->STREET1);
$otInfo["cityDeliv"] = trim($partner->CITY1);
$otInfo["zipDeliv"] = trim($partner->POSTL_COD1);
$otInfo["countryDeliv"] = trim($partner->COUNTRY1);
default:
// do nothing
break;
}
}
// Go through the dates info to get the wanted items
foreach ($ot->E1EDT13 as $qualf) {
switch ($qualf->QUALF) {
case "006":
$dtDeliv = trim($qualf->NTANF);
$timeDeliv = trim($qualf->NTANZ);
$otInfo["initialDtDeliv"] = convertToOtDateFormat($dtDeliv, $timeDeliv);
break;
case "007":
$initialDtShip = trim($qualf->NTANF);
$timeInitialDtShip = trim($qualf->NTANZ);
$otInfo["initialDtShip"] = convertToOtDateFormat($initialDtShip, $timeInitialDtShip);
break;
default:
// do nothing
break;
}
}
}
Hope this'll help someone!
I am trying to pull information into a page using my model. The issue is that I need to use an IN condition on my mysql using a variable.
Here is the code I use currently
$list_id = '1,3';
$clients = ListSubscriber::model()->findAll(array('condition'=>'list_id IN (:list_id)','params'=>array(':list_id'=>$list_id)));
I won't necessarily know how many numbers will be stored within $list_id, hence the need for a variable to work with the IN.
The code does execute without errors, but only seems to return the values for the first number of $list_id, so in this case it only finds users where the list_id = 1.
Any help is appreciated. I have found this question Yii addInCondition
However they are using static values, which does not resolve my issue.
When I do use static values, the code executes with results as expected.
You can use addInCondition :
$list_id = '1,3';
$criteria = new CDbCriteria();
$arr_list_id = explode(",",$list_id);
$criteria->addInCondition("list_id ", $arr_list_id );
$clients = ListSubscriber::model()->findAll($criteria);
$list_ids = array(1,3);
$clients = ListSubscriber::model()->findAllByAttributes(array('list_id'=>$list_ids));
I'm trying to write a script that will update an RSS XML file. I want it to take the existing file and add a new item to the top of the items list. I've previous gotten it to add to the end of the file, but now it's currently not adding the new item at all. I've been checking around online, but I still can't get it to work. Here is what I have so far:
$rssDoc = new DOMDocument();
$rss_file = $_SERVER['DOCUMENT_ROOT'].'/test_site/feed.xml';
$rssDoc->load($rss_file);
$items = $rssDoc->getElementsByTagName('item');
$newItem = $rssDoc->createElement('item');
$rssTitle = $rssDoc->createElement('title');
$rssTitle->appendChild($rssDoc->createTextNode($title));
$newItem->appendChild($rssTitle);
$rssDesc = $rssDoc->createElement('description');
$rssDesc->appendChild($rssDoc->createTextNode($string));
$newItem->appendChild($rssDesc);
$rssLink = $rssDoc->createElement('link');
$rssLink->appendChild($rssDoc->createTextNode($link));
$newItem->appendChild($rssLink);
$rssDate = $rssDoc->createElement('pubDate');
$rssDate->appendChild($rssDoc->createTextNode($pubDate));
$newItem->appendChild($rssDate);
$firstItem = $items->item(0);
$firstItem->insertBefore($newItem,$firstItem->firstChild);
$rssDoc->formatOutput = true;
echo $rssDoc->saveXML();
What am I missing?
"What am I missing?"
The output: $rssDoc->save( 'filename.xml' ) http://php.net/domdocument.save.php
I got it working. I changed these lines:
$firstItem = $items->item(0);
$firstItem->insertBefore($newItem,$firstItem->firstChild);
To this line:
$items->item(0)->parentNode->insertBefore($newItem,$items->item(0));
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.