using twilio, trying to return a list of text messages sent to a specific number...with no luck
foreach ( $client->account->sms_messages->To(+12345678901) as $sms ) { echo $sms->body; echo "</br>"; }
the problem is obviously the "To(+12345678901)"
I have tried using single and double quotes, numbers owned and not owned, and several other parameter formatting options, I cant seem to get lucky here. Please help.
Twilio Developer Evangelist here.
You've almost got it. The part you're missing is using the getIterator method for filtering. You pass this an array containing the data you're filtering on. Here's a code snippet:
foreach ($client->account->messages->getIterator(0, 50, array(
'To' => '+12345678901',
)) as $message) {
echo "From: {$message->from}\nTo: {$message->to}\nBody: " . $message->body;
}
You can read a bit more about filtering messages in our docs. The docs for our PHP helper library also have some good examples.
Related
I am having a small problem adding multiple dimensions to the API request for Search Console.
If I add the following to group by country it works fine.
$filters->setDimension("country");
$filters->setOperator("equals");
$filters->setExpression($country);
$filter->setFilters($filters);
$filter->setFilters(array($filters));
$request->setDimensionFilterGroups(array($filter));
But if I add another dimension below for device, it skips the country dimension and only runs the query with the device dimension. It's perfectly possible to run both according to this on the search console API site:
'filters': [{
'dimension': 'country',
'expression': 'ind'
}, {
'dimension': 'device',
'expression': 'MOBILE'
}]
So, any idea how I can use them both on a query?
It's probably simply some PHP code, but I can't find any documentation on multiple dimensions or any examples anywhere with PHP in mind.
It was simple.
$filters->setDimension("country");
$filters->setOperator("equals");
$filters->setExpression($country);
$filters2->setDimension("device");
$filters2->setOperator("equals");
$filters2->setExpression($device);
$filter->setFilters($filters);
$filter->setFilters(array($filters,$filters2));
$request->setDimensionFilterGroups(array($filter));
Works like a charm.
Many thanks for sharing this, Nick - it really helped!
One tiny thing: you won't need the following:
$filter->setFilters($filters);
as you're setting filters the right way with the next line of code.
Also, I was stuck on the following line:
$request->setDimensionFilterGroups(array($filter));
as I was passing the $filter object as it is instead of using an array.
I really found this counter-intuitive: this is the only object setDimensionFilterGroups method needs; I'm still wondering why it needs an array instead.
Cheers,
Sal
Nick's answer did helped me start but currently it isn't complete. To help other devs looking for an answer, hope this would help you:
$filter_group = new Google_Service_Webmasters_ApiDimensionFilterGroup;
$groups = array(['device', 'mobile', 'equals'], ['country', 'GBR', 'equals']);
$filters = array();
if($groups) {
foreach ($groups as $key => $group) {
$filters[$key] = new Google_Service_Webmasters_ApiDimensionFilter;
$filters[$key]->setDimension($group[0]);
$filters[$key]->setExpression($group[1]);
$filters[$key]->setOperator($group[2]);
}
$filter_group->setFilters($filters);
}
$request->setDimensionFilterGroups(array($filter_group));
Also take note, currently it won't work if in your filter group you have two or more same dimension but different value for filter or expression.
e.g.
$groups = array(['device', 'mobile', 'equals'], ['device', 'tablet', 'equals']);
It is because OR operation is currently not supported for filters.
Check here and this answer here.
I am using Phaxio for send FAX and it's working fine till now.
Now i have to add some extra stuff to it. I want to generate some of the data in new pages into same PDF(generate PDF on success of send fax by phaxio).
Currently its being generate new pages only when while it's come up at bottom of the page.
i tried following code by paging paging parameters as given on Phaxio official site http://www.phaxio.com/docs/paging/ but it's not working at all or might be i don't know how to use it.
Please take a look at following code.
require ("Phaxio.php");
$apiKeys['test']='xxxxxxxxxxxxxxxxxxxxxxxxxxx';
$apiSecrets['test']='xxxxxxxxxxxxxxxxxxxxxxxxxxx';
$apiHost='https://api.phaxio.com/v1/';
$filename='html_data.html';
$toNumber="my-10-digit-phone-no";
$phaxio=new Phaxio($apiKeys['test'], $apiSecrets['test'], $apiHost);
$phresult=$phaxio->sendFax($toNumber, $filename,
array('maxperpage' => '400','page' => '1'));
echo "<pre>";
print_r($phresult);
if ( !$phresult->succeeded() ) {
echo ("<H4>Error sending fax to $toNumber with " . $phresult->getMessage()."</H4>");
return FALSE;
}
else {
echo ("<H4>Your fax has been sent.</<H4>");
return TRUE;
}
After spending couple of hours i finally got a very silly but useful solution.
Actually my requirement was that in my FAX PDF there was number of repeated HTML was there like generate invoice in same format(using loop), and i really need like every invoice HTML should be in separate PDF page.
So I've simply used CSS style="page-break-before:always;" and i was done with my issue.
1) via CSS - for the advanced HTML users:
<p style="page-break-after:always;"></p>
2) with a simple comment:
<p><!-- pagebreak --></p>
I'm playing around with the Amazon developer's API and I'm not getting anything.
Here is my code. I am using echo to see if anything is happening and all I am getting is a blank webpage. I expected the array of search results to be echoed.
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
require_once('Zend/Service/Amazon.php');
$amazon = new Zend_Service_Amazon('AKIAJQBYUXIFWUIX6W6A', 'US', 'YGV9zePfKejV6C3dpaP/NtnhjGLfWQsccdGSSL50');
$results = $amazon->itemSearch(array('SearchIndex' => 'Books',
'Keywords' => 'php'));
foreach ($results as $result) {
echo $result->Title . '<br />';
}
?>
getting a blank page still
Your page is blank because you are no getting any results:
This is the $results dump using your published code:
Amazon object(Zend_Service_Amazon_ResultSet)#103 (4) {
["_results":protected] => object(DOMNodeList)#105 (0) {
}
["_dom":protected] => object(DOMDocument)#101 (0) {
}
["_xpath":protected] => object(DOMXPath)#104 (0) {
}
["_currentIndex":protected] => int(0)
}
There are several issues to resolve to make this work, the biggest one being this:
The following changes will take effect on 11/1/2011: Associate Tag Parameter: Every request made to the API should include
a valid Associate Tag. Any request that does not contain a valid
Associate Tag will be rejected with an appropriate error message. For
details on the Associate Tag parameter, please refer to our Developer
guide.
Currently the constructor for Zend_Service_Amazon does not include the Associate Tag parameter and the _prepareOptions() method does not set the option.
I'm sure someone has a fix for this, otherwise it's time to dig in and extend... Good Luck
Amazon Product Advertising API
Changes to Product Advertising API
The Zend_Service_Amazon is out of date and uses old WSDL.
see http://zendframework.com/issues/browse/ZF-12046
wait for 1.12 or use the provided batch file.
'm using GAPI version 1.3 I have added a custom variable in GA code like this:
**_gaq.push(['_setCustomVar', 1, 'Member', '<?php echo $member_id; ?>, 3]);**
And its working fine..
Now I need to fetch the data from GA: so my request to GA is like this:
**https://www.google.com/analytics/feeds/data?
ids=XXXXXXXXXXX&
dimensions=ga:customVarValue1,ga:pagePath&
metrics=ga:pageviews,ga:uniquePageviews,ga:bounces,ga:exits&
filters=ga:pagePath=#event_details.php;ga:customVarValue1=2004036442&
start-date=2011-04-20&
end-date=2011-05-04&
max-results=50**
I need to fetch data from GA where pagePath=#event_details.php AND ga:customVarValue1=2004036442
But this is not resulting anything...
When I changed the filters in the following why its resulting all the pagePath = event_details.php and its working fine.. filters=ga:pagePath=#event_details.php
But I need get the page path with the particular member ID that is why I used the condition as below: filters=ga:pagePath=#event_details.php;ga:customVarValue1=2004036442&
So any one have idea about this?? Please help..
After looking at the code you posted in Google Docs, I see your problem.
Try using this as your filter.
$filter = 'pagePath =# ' . $filter_text[$tab] . ' && customVarValue1 == 2004036442'
The function you are passing $filter to does a cleanup process that escapes any reserved characters with a backslash. Your customVariable is being sent with a slash at the end, which is why it's not returning any matches.
Once I've identified identified the email addresses of my list segment (using get_emails() custom function, I am setting up my list segment as follows:
$batch = get_emails();
//now create my list segment:
$api->listStaticSegmentAdd(WEDDING_LIST_ID, 'new_wedding_guests');
$api->listStaticSegmentMembersAdd(WEDDING_LIST_ID, 'new_wedding_guests', $batch);
//do I build vars for a campaign?
$options = array (
'list_id' => WEDDING_LIST_ID, //What value id's my list segment?
'subject' => 'Alpha testing.',
'from_email' => 'wedding#juicywatermelon.com',
'from_name' => 'Pam & Kellzo',
'to_name' => $account->name,
);
From here can I use a basic campaign and send it?
$content['text'] = "Some text.";
$content['html'] = get_link($account);
$cid = $api->campaignCreate('regular', $options, $content);
$result = $api->campaignSendNow($cid);
I'm not sure if I'm understanding the api documentation correctly. I also tried 'list_id' => 'new_wedding_guests'; which failed to create a campaign.
Thanks!
I'll assume this is test code and just make the cursory mention of how you probably don't need to be creating a new Static Segment every time. However, your call to add members is not going to work. Per the listStaticSegmentMembersAdd documentation, you should be passing the static segment id, not the name of it. Also note that the docs cross-reference themselves when input params can come from other calls - that parameter there is a good example (it also happens to be returned by listStaticSegmentAdd).
Your options for campaignCreate look like a good start. The documentation for it has examples below - those examples are included in the PHP MCAPI wrapper you likely downloaded. As per above, the list_id you need is the one for the list you used in the listStaticSegment calls (also linked in the documentation).
Now the real key - further down in the campaignCreate docs is the segment_opts parameter - that is how you control segmentation. Follow the link it gives you and you'll find tons of info on the ways you can do segmentation, including using a static_segment.
Hopefully all of that made sense, if not, take a step back and check out these links (and play with segmentation in the app), then it should:
Introduction to MailChimp List Management
How can I send to a segment of my list?
Our Release Info on how Static Segments are used