I am able to successfully get results back from a call to headObject like this. But then I can't access what's in $result as result is an object (Guzzle\Service|Resource\Model) and the data I see in it is obviously in protected variables meaning I have to use an object call to get it. But how do I know what the method call should be?
$result = $client->headObject([
'Bucket' => $bucket, // REQUIRED
'Key' => $key // REQUIRED
]);
$relevantmetaData = array();
$relevantmetaData['LastModified'] = $result->data['LastModified'];
The link here doesn't mention a method to get at $data
I guess I should just have tried get(), it works.
$relevantmetaData['LastModified'] = $result->get('LastModified');
Related
I need to create line chart for my twitter followers . I have used following code to list the followers details.
$parameters = array('include_user_entities' => true);
$response = $this->api->get('followers/list.json', $parameters);
Its working fine .But its doesn't probvide following date details. How can I get following date details using twitter api
If you write:
$parameters = array('include_user_entities' => true);
$parameters = array();
The second command overwrite the first. Thus $parameters contains an empty array. Try with this:
$parameters = array('include_user_entities' => true);
$response = $this->api->get('followers/list.json', $parameters);
There is no way in the API to tell when someone followed you.
Take a look at the API reference - https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-followers-list
The only date in the returned object is created_at - that refers to when the account was created, not when it followed you.
I'm using jasperserver in my php/Symfony to generate my reports, and i pass parameters ad everything works fine. But now i want to pass an array containing the list of my user's name to jrxml file i really don't know if it's possible. i mean i know that we can do it with javabeans or creating a datasource, but in my case i mustn't use a database plus i use php.
So if anyone know how to pass the array and fetch it in the jrxml file to display all the values i would be so grateful
so here is the code i'm want to use
$users = $em->getRepository('UserBundle:Utilisateur')->getAll();
$params = array(
"montantEnLettre" => $montantEnLettre,
"policeGroupeLibelle" => $contrat->getProduit()->getLibelle(),
"montanttotal" => $contrat->getMontantTotale(),
"utilisateurs" => $users
);
$d = new Client(
"http://127.0.0.1:8080/jasperserver",
"jasperadmin",
"jasperadmin"
);
$js = $d->jobService();
$d->setRequestTimeout(60);
$info = $d->serverInfo();
$report = $d->reportService()->runReport('/reports/epargne', 'pdf',null,null,$params);
I don't know if i can pass the users as a parameter and i have no idea how to fetch it my jrxml file
I'm using an external class (Zebra_cURL) to execute multiple HTTP GET requests. It worked in the following way:
$items = array(
0=>array('url' => 'url0'),
1=>array('url' => 'url1'),
2=>array('url' => 'url2'),
3=>array('url' => 'url3'),
);
$curl = new Zebra_cURL();
$curl->get(array_column($urls,'url'),'scan_item',$moreimfo);
function scan_item($result,$moreimfo){
$items[$key]['size'] = strlen($result->body);
}
So my callback should fill up my $items array with more info for each url (in my case - size of the page). So there is a missing $key variable.
This class supports extra parameters in the callbacks ($moreimfo in my case). BUT as I understand the data passing to each callback will be always the same.
$result object containing the original url info ($result->info['url']). So I COULD use it to find needed array element. However this looks too inefficient in case the size of an array will be big enough.
I think that I should find how to pass an array member key information for EACH callback execution. Is it possible without modifying the original class?
If you use the url as key in the $items array the solution could be something like
<?php
$items = [
'url0'=>array('url' => 'url0'),
'url1'=>array('url' => 'url1'),
'url2'=>array('url' => 'url2'),
'url3'=>array('url' => 'url3'),
];
$curl = new Zebra_cURL();
$curl->get(
array_keys($items),
function($result) use (&$items) {
$key = $result->info['url'];
$items[$key]['size'] = strlen($result->body);
}
);
using an anymous function that "Imports" the $items array via reference.
While it doesn't solve the original problem of passing a reference to the according array element to the callback, the following should be very fast (as noted in the comments, PHP Arrays are implemented using a hashtable).
$items = array(
0=>array('url' => 'url0'),
1=>array('url' => 'url1'),
2=>array('url' => 'url2'),
3=>array('url' => 'url3'),
);
$lookup=array();
foreach($lookup as $k=>$v) {
$lookup[$v['url']]=$k;
}
$curl = new Zebra_cURL();
$curl->get(array_column($urls,'url'),'scan_item',$moreimfo);
function scan_item($result,$moreimfo){
global $lookup,$items;
$items[$lookup[$result->info['url']]]['size'] = strlen($result->body);
}
Probably you may consider using an OOP-approach, with the callback as a method, then the global-izing of the arrays shouldn't be necessary if you use $this->anyMember
I'm trying to get products from Magento API with catalogProductList (soap v2) here is my function.
public function get_products() {
$products = array();
$login = $this->login_info();
$proxy = new SoapClient($login['url']);
$sessionId = $proxy->login($login['user'], $login['pass']);
$result = $proxy->catalogProductList($sessionId);
foreach($result as $value) {
$products[] = $proxy->catalogProductInfo($sessionId, $value->product_id);
}
echo "<pre>";
var_dump($products);
echo "</pre>";
}
However because the request it's in a loop it will make for each product a request to Magento API.
I'm wondering if there is a solution to get multiple products info (based on provided product_id) in the same request. Maybe 50 or 100 products info for each request I think will reduce a lot the time of getting all the products.
I have found on http://www.magentocommerce.com/api/soap/introduction.html
$params = array('filter' => array(
array('key' => 'status', 'value' => 'pending'),
array('key' => 'customer_is_guest', 'value' => '1')
));
$result = $client->salesOrderList($sessionId, $params);
but from my understanding it's more about filtering the products so I don't know if it helps too much.
Looks like you're calling the catalogProductList twice, first time outside the loop and the second time inside the loop passing invalid arguments, the doc here is showing that you only need to use the method once passing the session id plus you are able to pass two extra optional arguments (array of filters and the store view id or code) additionally if the returned result catalogProductEntity is not enough you can override that part of the API adding extra product information for example the media images.
I'm able to query my dynamodb tables, but I only want to retrieve the actual value. I don't want the formatting output. This same question has been answered here for Java, but I'm looking for the PHP solution:
Retrieving just the item value from a dynamodb table?
Here is my getitem query:
$response = $dynamodb->getItem(array(
"TableName" => $tableName,
"ConsistentRead" => true,
"Key" => array(
"userguid" => array(Type::STRING => $userguid)
),
"AttributesToGet" => array("token")
));
print_r($response["Item"]["token"]);
Here is the output:
Array
(
[S] => 9d194513
)
All I want to get back is:
9d194513
I assumed the logical answer would be to change the last line to:
print_r($response["Item"]["token"]["S"]);
But then my code doesn't return anything at all. Obviously still learning PHP here, and any help would be appreciated.
Don't use print_r function, just either echo your variables
echo $response["Item"]["token"]["S"];
or store in a variable for later use
$res_token = $response["Item"]["token"]["S"];
You can also use the getPath convenience method built into the Model object that the SDK returns for operations.
echo $response->getPath('Item/token/S');
For more information about working with responses in the SDK, see the Response Models page in the AWS SDK for PHP User Guide.
Though it's an old question but for anyone coming to this page for seeking answer, this is how I have done it.
getItem returns a Resultobject. You can call the get() function of the SDK, which will give you an array containing the exact value.
$params = [
"TableName" => "EpgApiAccessCount",
"Key" => $this->marshalJson('
{
"ApiUserKey": "' . $apiUserkey . '"
}
')
];
$result = $this->client->getitem($params);
if (!$result instanceof ResultInterface) {
return 0;
}
$item = $this->unmarshalItem($result->get("Item"));
return $item["AccessCount"];
Of course your value and table name will be different, and you can print or do anything else with the value.