AWeber API: subscribers->create() not working as expected in script - php

The extent to which the AWeber API is not clearly documented cannot be underscored enough (nor do their example scripts work very well). The below script was written so I could subscribe one user to multiple lists selected from a form.
Anyway, this script works when the subscribers->create method is commented out. I'm able to see my separate list ids feed to the list urls and then the list array data is fetched and returned. But once the create method is added back in, it only does one trip through the loop, subscribes the email parameter to the first list it finds and then the script stops:
<!DOCTYPE html>
<html>
<body>
<?php
require_once('aweber_api/aweber_api.php');
require_once('aweber_api/aweber_creds.php');
print "----<br>";
$aweber->adapter->debug = true;
print "----<br>";
//call the api key...
$aweber = new AWeberAPI($consumerKey, $consumerSecret);
$account = $aweber->getAccount($accessKey, $accessSecret);
$feeds = array_values($_GET);
//print form array
print "FORM ARRAY ";
print_r ($feeds);
echo "--<br>";
foreach($feeds[1] as $feed){
echo "--<br>";
try {
print "<br> Feed : $feed";
$listURL = "/accounts/{$account_id}/lists/{$feed}";
$list = $account->loadFromUrl($listURL);
$lists = $account->lists->find(array('name' => $listName));
print_r ($list);
print "<br><br><br>";
# create a subscriber
$params = array(
'email' => $feeds[0],
);
$subscribers = $list->subscribers;
$new_subscriber = $subscribers->create($params);
print "HERE " . $new_subscriber->email;
# success!
print "$new_subscriber->email was added to the $list->name list!";
} catch(AWeberAPIException $exc) {
print "<h3>AWeberAPIException:</h3>";
print " <li> Type: $exc->type <br>";
print " <li> Msg : $exc->message <br>";
print " <li> Docs: $exc->documentation_url <br>";
print "<hr>";
}
}
?>
</body>
</html>
And for the sake of context, here are some form parameters being passed into this script:
somehostnamehere.com/phptest/aweber_api/hltmt_addsubsv1.php?email=user22344%40gmail.com&aweber_list%5B%5D=2531241&aweber_list%5B%5D=2531242&aweber_list%5B%5D=2531243&aweber_list%5B%5D=2531244

you should have such : ...php?email=user22344#gmail.com
so, use urldecode(), for example:
$final = 'somehostnamehere.com/phptest/aweber_api/hltmt_addsubsv1.php?'. urldecode('email=user22344%40gmail.com&aweber_list%5B%5D=2531241&aweber_list%5B%5D=2531242&aweber_list%5B%5D=2531243&aweber_list%5B%5D=2531244');
echo $final;

Related

firestore display values of data in php

how to display each record's values?
$collectionReference = $this->fsdb->collection('orders');
$documentReference = $collectionReference->document('MSKpcuedwxNmdLn2Ydsp');
$snapshot = $documentReference->snapshot();
echo "Hello " . $snapshot['userId'];
I am receiving this error:
ErrorException
Object of class Google\Cloud\Firestore\DocumentReference could not be converted to string
print_r() function works correctly but how to access each individual record?
I have been searching for hours to get this solved but I found no reference on web
Please help me in here...
A snapshot contains both data and metadata about the document. To get the data you need to call its data() method:
$collectionReference = $this->fsdb->collection('orders');
$documentReference = $collectionReference->document('MSKpcuedwxNmdLn2Ydsp');
$snapshot = $documentReference->snapshot();
if ($snapshot->exists()) {
printf('Document data:' . PHP_EOL);
echo "Hello " . $snapshot->data()['userId'];
} else {
printf('Document %s does not exist!' . PHP_EOL, $snapshot->id());
}
Also see the Firebase documentation on getting a document from Firestore.

Echo XML Elements with file_get_contents

i'm successfully managing to pull in the information in this feed:
http://api.zoopla.co.uk/api/v1/zed_index?area=yo1&output_type=outcode&api_key=XXXXMYAPIKEYGOESHEREXXXXX
I'm doing this with the following code:
<p><?php $postcode = get_the_title(); $str = urlencode($postcode); $url = "http://api.zoopla.co.uk/api/v1/zed_index?area=$str&output_type=outcode&api_key=5dj2d5x8kd2z2vnk9g52gpap"; $string = file_get_contents($url); echo $string;?></p>
However, this just echos the following output:
DE45 http://www.zoopla.co.uk/home-values/de45 53.258037 53.138911 -1.580861 -1.79776 England Derbyshire 53.198474 -1.6893105 DE45 368929 375424 362103 372926 333441 329349 322644 368056
How could i adapt my existing code to successfully echo individual elements from the feed, for example just the following fields wrapped in tags:
zed_index
zed_index_1year
zed_index_2year
Thanks for your help!
You could use simplexml_load_file() to get an array which will contains every of your XML tags :
<p>
<?php
$XML_url = 'http://api.zoopla.co.uk/api/v1/zed_index?area=yo1&output_type=outcode&api_key=XXXXMYAPIKEYGOESHEREXXXXX';
$XML_parsed = simple_xml_load($XML_url);
// print for debug
echo '<pre>';
print_r( $XML_parsed );
echo '</pre>';
// Access one of the tag
$tagName = $XML_parsed['tagName'];
// Access a nested tag
$nestedTag = $XML_parsed['first_tag']['second_tag'];
?>
</p>

Load XML File in PHP and add Child if not exists

i want to load XML data into my php file with address data.
Each address should also have coordinates - if not they should be added. So i am doing the following:
$xmlDatei = "AddressData.xml";
$xml = simplexml_load_file($xmlDatei);
for($i=0,$size=count($xml);$i<$size;$i++){
if($xml->RECORD[$i]->ADDRESS->LAT != NULL){
//get lat and lng stuff here...
$lat = .......
$lng = .......
echo "lat: " . $lat; // Test echo WORKING
echo "lng: " . $lng;
// Now i want to add the data to the xml
$xml->RECORD[$i]->ADDRESS->addAttribute('LAT', $lat);
$xml->RECORD[$i]->ADDRESS->addAttribute('LNG', $lng);
$xml->saveXML();
}
// Test echo NOT WORKING
echo $xml->RECORD[$i]->ADDRESS->LAT;
echo $xml->RECORD[$i]->ADDRESS->LNG;
}
So it seems like the addAttribute is not working properly here.
What am I doing wrong???
Your echo is looking for a child element called LAT:
echo $xml->RECORD[$i]->ADDRESS->LAT;
But you have added an attribute, so you need to use different syntax:
echo $xml->RECORD[$i]->ADDRESS['LAT'];
You are adding attributes to the ADDRESS tag, not nodes.
Try this:
echo $xml->RECORD[$i]->ADDRESS['LAT'];
echo $xml->RECORD[$i]->ADDRESS['LNG'];

Call a php file in webroot from a controller using cake php

I have a php file in webroot.which returns an array of filenames.So I want to call this php file from a controller.can u give me an ideaa how ll I do this...??the content of this php file is given below:
<?php
//if($_SERVER['REMOTE_ADDR']=='10.1.31.77'){debugbreak();}
include ("../vendors/xmlrpc.inc");
?>
<html>
<head>
<title>XML-RPC PHP Demo</title>
</head>
<body>
<h1>XML-RPC PHP Demo</h1>
<?php
$client = new xmlrpc_client('/individual-trade-server-manager/list-binaries-on-trade-server.php',
'125.20.11.245', 80);
//$client->return_type = 'phpvals';
//$client->setDebug ( 2 );
$stringToEcho = 'Hello World';
// Send a message to the server.
$message = new xmlrpcmsg('rpc.FnListAllBinaryFiles',array(php_xmlrpc_encode ( $stringToEcho )));
$result = $client->send($message);
// Process the response.
if (!$result) {
print "<p>Could not connect to HTTP server.</p>";
} elseif ($result->faultCode()) {
print "<p>XML-RPC Fault #" . $result->faultCode() . ": " .
$result->faultString();
} else {
$output=php_xmlrpc_decode($result->value());
$output=explode('*',$output);
//echo "<pre>";
// print_r($output);
}
//echo "<pre>";
// print_r($output);
?>
<table>
<tr><th>Binary Filenames</th></tr>
<?php
foreach($output as $val)
{
//echo "<pre>";
//print_r($val);
?>
<tr><td><?php echo $val; ?></td></tr>
<?php
}
?>
</table>
</body></html>
So i just want call this page from a controller so how ll i call this page,and set this this $output array in the controller.
thanks in advance
I would suggest you create a class with static function in the vendors folder.
The static function will return your array and you will be able to invoke the method from your controller using Myclass::mymethod();

An Ajax request is taking 6 seconds to complete, not sure why

I am working on a user interface, "dashboard" of sorts which has some div boxes on it, which contain information relevant to the current logged in user. Their calendar, a todo list, and some statistics dynamically pulled from a google spreadsheet.
I found here:
http://code.google.com/apis/spreadsheets/data/3.0/reference.html#CellFeed
that specific cells can be requested from the sheet with a url like this:
spreadsheets.google.com/feeds/cells/0AnhvV5acDaAvdDRvVmk1bi02WmJBeUtBak5xMmFTNEE/1/public/basic/R3C2
I briefly looked into Zend GData, but it seemed way more complex that what I was trying to do.
So instead I wrote two php functions: (in hours.php)
1.) does a file_get_contents() of the generated url, based on the parameters row, column, and sheet
2.) uses the first in a loop to find which column number is associated with the given name.
So basically I do an ajax request using jQuery that looks like this:
// begin js function
function ajaxStats(fullname)
{
$.ajax({
url: "lib/dashboard.stats.php?name="+fullname,
cache: false,
success: function(html){
document.getElementById("stats").innerHTML = html;
}
});
}
// end js function
// begin file hours.php
<?php
function getCol($name)
{
$r=1;
$c=2;
while(getCell($r,$c,1) != $name)
{ $c++; }
return $c;
}
function getCell($r, $c, $sheet)
{
$baseurl = "http://spreadsheets.google.com/feeds/cells/";
$spreadsheet = "0AnhvV5acDaAvdDRvVmk1bi02WmJBeUtBak5xMmFTNEE/";
$sheetID = $sheet . "/";
$vis = "public/";
$proj = "basic/";
$cell = "R".$r."C".$c;
$url = $baseurl . $spreadsheet . $sheetID . $vis . $proj . $cell . "";
$xml = file_get_contents($url);
//Sometimes the data is not xml formatted,
//so lets try to remove the url
$urlLen = strlen($url);
$xmlWOurl = substr($xml, $urlLen);
//then find the Z (in the datestamp, assuming its always there)
$posZ = strrpos($xmlWOurl, "Z");
//then substr from z2end
$data = substr($xmlWOurl, $posZ + 1);
//if the result has more than ten characters then something went wrong
//And most likely it is xml formatted
if(strlen($data) > 10)
{
//Asuming we have xml
$datapos = strrpos($xml,"<content type='text'>");
$datapos += 21;
$datawj = substr($xml, $datapos);
$endcont = strpos($datawj,"</content>");
return substr($datawj, 0,$endcont);
}
else
return $data;
}
?>
//End hours.php
//Begin dashboard.stats.php
<?php
session_start();
// This file is requested using ajax from the main dashboard because it takes so long to load,
// as to not slow down the usage of the rest of the page.
if (!empty($_GET['name']))
{
include "hours.php";
// GetCollumn of which C#R1 = users name
$col = getCol($_GET['name']);
// then get cell from each of the sheets for that user,
// assuming they are in the same column of each sheet
$s1 = getcell(3, $col, 1);
$s2 = getcell(3, $col, 2);
$s3 = getcell(3, $col, 3);
$s4 = getcell(3, $col, 4);
// Store my loot in the session varibles,
// so next time I want this, I don't need to fetch it
$_SESSION['fhrs'] = $s1;
$_SESSION['fdol'] = $s2;
$_SESSION['chrs'] = $s3;
$_SESSION['bhrs'] = $s4;
}
//print_r($_SESSION);
?>
<!-- and finally output the information formated for the widget-->
<strong>You have:</strong><br/>
<ul style="padding-left: 10px;">
<li> <strong><?php echo $_SESSION['fhrs']; ?></strong> fundraising hours<br/></li>
<li>earned $<strong><?php echo $_SESSION['fdol']; ?></strong> fundraising<br/></li>
<li> <strong><?php echo $_SESSION['chrs']; ?></strong> community service hours<br/></li>
<li> <strong><?php echo $_SESSION['bhrs']; ?></strong> build hours <br/></li>
</ul>
//end dashboard.stats.php
I think that where I am loosing my 4 secs is the while loop in getCol() [hours.php]
How can I improve this, and reduce my loading time?
Should I just scrap this, and go to Zend GData?
If it is that while loop, should i try to store each users column number from the spreadsheet in the user database that also authenticates login?
I didn't have the proper break in the while loop, it continued looping even after it found the right person.
Plus the request take time to go to the google spreadsheet. About .025 second per request.
I also spoke with a user of ZendGdata and they said that the request weren't much faster.

Categories