I am using the icontact php api. I want to get the last contact who entered the list so in the icontact api php I have this:
<php
public function getContacts() {
// Make the call and return the data
return $this->makeCall("/a/{$this->setAccountId()} /c/{$this->setClientFolderId()}/contacts?listId=49626&status=total&createDate=2015-02-16&createDateSearchType=gt", 'GET');
}
?>
than I use this to call it:
<?php
$oiContact = iContactApi::getInstance();
try {
var_dump($oiContact->getContacts());
} catch (Exception $oException) { // Catch any exceptions
var_dump($oiContact->getErrors());
}
$obj = $oiContact->getLastResponse();
$data = json_decode($obj,TRUE);
echo $data['contacts'][0]['email'];
echo $data['contacts'][0]['commitmentscore'];
echo $data['contacts'][0]['firstName'];
echo $data['contacts'][0]['phone'];
?>
It keeps giving me the same contact it is because the 0 in the echo but how can I make that a variable or an if condition just not sure how
paste bins with full code
http://pastebin.com/SBf73UNb //call
http://pastebin.com/CuGcCvU1 //api
This worked
/contacts?listId=49626&orderby=createDate:desc&limit=1", 'GET');
Got it from this page
http://www.icontact.com/developerportal/documentation/advanced-users/
I think you can use orderby option,
check this link
sample they used
Get all contacts on a list ordered by First Name GET https://app.sandbox.icontact.com/icp/a/<accountId>/c/<clientFolderId>/contacts?orderby=firstName
Instead of firstname you can use date, something like normal SQL query doing then fetch only first contact.
Also the return data will be always array so you have to run within a foreach for iterate the data.
Hope it helps.
Related
I've been trying for 3 days to get PHP to show the ID from this test JSON using PHP and httpful.
Anyone have any ideas as i've tried loads of different combinations and even tried created a handler to decode as an array... I just suck at PHP ?
// Make a request to the GitHub API with a custom
// header of "X-Trvial-Header: Just as a demo".
<?php
include('\httpful.phar');
$url = "https://jsonplaceholder.typicode.com/posts";
$response = Httpful\Request::get($url)
->expectsJson()
->send();
echo "{$response[0]['id']}";
?>
My output... still nothing
You are not properly indexing the return value.
The response is a mixed value. So you should do something like below to get what you are looking for.
<?php
include('\httpful.phar');
$url = "https://jsonplaceholder.typicode.com/posts";
$response = Httpful\Request::get($url)
->expectsJson()
->send();
echo $response->body[0]->id;
?>
this is my first post. So basically I am trying to make a php file that returns the value of a website.
Here's what I got so far:
<?php
function GetRank($userId,$groupId) {
$url = "http://www.roblox.com/Game/LuaWebService/HandleSocialRequest.ashx?method=GetGroupRank&playerid=$userId&groupid=$groupId";
//echo $userId,$groupId;
//$response = readfile($url); // works but returns this (READ HERE)'<Value Type="integer">1337</Value>32'
if ($response) {
return $response;
}
return 'Failure';
}
?>
<Value Type="integer">1337</Value>32
I don't want to have it returning the above, as it currently does, I wanted it to return 1337. No clue how, I never did this before.
An example link:
http://www.roblox.com/Game/LuaWebService/HandleSocialRequest.ashx?method=GetGroupRank&playerid=25608009&groupid=228876
Thanks in advance I hope u guys understand me q.q
You can use the function below which will remove html tags from a string.
strip_tags($response);
Im trying to create a rest api in slim.php. What i want is actually just two function. one for retrieving all records from a table as JSON. and one for retrieving a record by its ID.
This far my index/api file looks like this below. Now how do i connects do the database? How do i return it as json?
<?php
require 'Slim/Slim.php';
\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim();
$app->get(
'/',
function () {
echo "hola!";
}
);
$app->run();
I have manage to get something going. I get the result back, but not as pure json. I can't see it as son in the console. Even tjo it gets written out in the browser. Current code:
$app->get('/', function () {
$db = connect_db();
$result = $db->query( 'SELECT * FROM test;' );
while ( $row = $result->fetch_array(MYSQLI_ASSOC)){
$data[] = $row;
}
echo json_encode($data);
});
A restfull route will look something like :
api/resources // to get all records
api/resources/{id} // to get a specific record
If you're using MVC architecture then in your controller you'll have two methods, one to get all records and the other to get a specific record. I'm not sure which interface Slim implements to connect to database but you can google it.
to return your result as json, you can use PHP's built-in function json_encode :
// $result = SQL query
return json_encode($result);
And I think you should think about paginating your recovered data, because returning a big number of data as json is not a good practice.
Good luck.
This script isn't working so good.
<?php
//include twitter class
require('classes/twitter.php');
$twitter = new Twitter('custToken', 'custSecret');
// set tokens
$twitter->setOAuthToken('blah blah');
$twitter->setOAuthTokenSecret('blah blah');
//$tweet = "This tweet was posted from a custom php script.";
//$twitter->statusesUpdate($tweet); // <-- this works!
$friends = $twitter->friendsList('tynamite');
foreach ($friends as $friend){
print_r($friend);
echo "<hr>";
}
?>
I want to display all my Twitter friends (everyone I follow) in a list.
The result I am getting is this.
Could anyone please help on this?
You should pass a cursor. You could use something like the code below (untested and just pseudo-code):
while($count == 20) {
$friends = $twitter->friendsList('tynamite', $cursor);
$count = count($friends);
$cursor++;
.. your code ..
}
twitter uses json to return its results. you need to parse the results returned and pull out the information you need. check this blog out for an example of how to use php to parse json
I'm using Joomla Framework to create component that displays options from a MySQL table.
Because each option has a lot of various parameters they are being set as json arrays in custparams field.
This function extracts these custom parameters from each option based on option id.
JSON data is decoded and written into stdObject:
$_oparams=null;
function _custParamsOpt($pid)
{
$query='SELECT custparams FROM #__mycomponent_options'
.' WHERE id = '.(int)$pid;
$this->_db->setQuery( $query);
$paramdata=$this->_db->loadResult();
if (!empty($paramdata))
{
$custom=json_decode($paramdata);
foreach ($custom as $custom_params)
{
if ($custom_params->pkey=='elemvert') $this->_oparams->elemvert=$custom_params->pvalue;
if ($custom_params->pkey=='elemhor') $this->_oparams->elemhor=$custom_params->pvalue;
if ($custom_params->pkey=='minwidth') $this->_oparams->minwidth=$custom_params->pvalue;
if ($custom_params->pkey=='maxwidth') $this->_oparams->maxwidth=$custom_params->pvalue;
if ($custom_params->pkey=='minheight') $this->_oparams->minheight=$custom_params->pvalue;
if ($custom_params->pkey=='maxheight') $this->_oparams->maxheight=$custom_params->pvalue;
}
return true;
} else {
return false;
}
}
Is it possible to write this data as:
$this->_oparams->$pkey=$custom_params->pvalue;
so I can avoid listing all the parameters?
In the code later I check parameters in this way:
if (!empty($this->_oparams->maxheight)) $htmlout.="\t\t\t\t<input type=\"hidden\" name=\"maxheight".$rowx->id."\" id=\"maxheight".$rowx->id."\" value=\"".$this->_oparams->maxheight."\" />";
I believe this is what you are looking for:
...
foreach ($custom as $custom_params)
$this->_oparams->{$custom_params->pkey} = $custom_params->pvalue;
}
...