Im not sure why, never used to use arrays anyway till now. Well, I have this code:
$inventoryJsonUrl = 'http://steamcommunity.com/inventory/'.$steamID.'/730/2?l=english&count=5000';
$inventoryJsonGet = file_get_contents($inventoryJsonUrl);
$inventories = json_decode($inventoryJsonGet, TRUE);
foreach($inventories['success']['rgInventory'] as $key => $description)
{
echo $description['classid'];
}
And Im getting this error:
Warning: Invalid argument supplied for foreach()
I have also another trouble, how to get name/value or whatever it is thatis market on this image (it is also the Json im using: https://i.imgur.com/oaNCquW.png
If I can also ask, for any good but "simple" JSON tutorials for things that im using here?
Thanks for help.
Here you need to do this:
foreach($inventories['rgInventory'] as $key => $description)
{
echo $description['classid'];
}
Note: Steam API is a complicated API and often doesn't work the way you would like to. If you are calling more than 30 times per minute, make sure to use proxies.
Ok, i thinked i was able to do this easily but i cant figure how.
I have tried in many ways i found here and in other pages but nothing works; i spent two days with this, but i finally decided to register here and ask.
So here is my karma:
http://api.bitcoinvenezuela.com/DolarToday.php?json=yes
That url generates this json:
{"_antibloqueo":{"mobile":"https://dt.wordssl.net","video":"","corto_alternativo":"https://bit.ly/venezuela911","enable_iads":"","enable_admobbanners":"ca-app-pub-8212448379596570/1946229161","enable_admobinterstitials":"","alternativo":"68747470733a2f2f64626d7a647431663034653531632e636c6f756466726f6e64742e6e6574","alternativo2":"68747470733a2f2f64626d7a647431663034653531632e636c6f756466726f6e64742e6e6574","notifications":"https://d3c134ru0r3b0g.cloudfront.net","resource_id":"33504 A"},"_labels":{"a":"DOLARTODAY","a1":"DOLAR CUCUTA","b":"IMPLICITO","c":"DICOM","d":"DOLAR BITCOIN","e":"DIPRO"},"_timestamp":{"epoch":"1513837984","fecha":"Diciembre 21, 2017 02:33 AM","fecha_corta":"Dic 21, 2017","fecha_corta2":"Dic 2017","fecha_nice":"Diciembre 21, 2017","dia":"Jueves","dia_corta":"Jue"},"USD":{"transferencia":121205.72,"transfer_cucuta":121205.72,"efectivo":10330.84,"efectivo_real":122608.7,"efectivo_cucuta":122608.7,"promedio":121205.72,"promedio_real":11311,"cencoex":10,"sicad1":94496.22,"sicad2":11311,"bitcoin_ref":94496.22,"localbitcoin_ref":94496.22,"dolartoday":121205.72},"EUR":{"transferencia":143581.51,"transfer_cucuta":143581.51,"efectivo":12259.61,"efectivo_real":145502.19,"efectivo_cucuta":145502.19,"promedio":143581.51,"promedio_real":13422.76,"cencoex":11.87,"sicad1":112138.66,"sicad2":13422.76,"dolartoday":143581.51},"COL":{"efectivo":0.023,"transfer":0.023,"compra":0.023,"venta":0.02},"GOLD":{"rate":1265.9},"USDVEF":{"rate":10.02959},"USDCOL":{"setfxsell":2820,"setfxbuy":2740,"rate":3606,"ratecash":2825,"ratetrm":3005.76,"trmfactor":0.2,"trmfactorcash":0.06},"EURUSD":{"rate":1.18672},"BCV":{"fecha":"1513569600","fecha_nice":"Diciembre 18, 2017","liquidez":"100.643.049.794","reservas":"9.742.000"},"MISC":{"petroleo":"56,14","reservas":"9,7"}}*
I need read the json it generates to get the bolded values (only 2 values i need from there); I have tried with curl, file_get_contents, and many other ways, but nothing works.
Basically, I can not understand WHY this code do not works:
<?php
$url = 'http://api.bitcoinvenezuela.com/DolarToday.php?json=yes';
$obj = json_decode(file_get_contents($url), true);
echo $obj;
?>
I get a warning:
Warning: file_get_contents(http://api.bitcoinvenezuela.com/DolarToday.php?json=yes): failed to open stream: Connection timed out in /home/u704982448/public_html/lbapi.php on line 3
Any idea what is happening here? Where is the fail?
EDIT: Looks like the problem here is that my server ip is blocked. Any workaround for this?
Thanks to everyone.
You are trying to print an array in echo statement so its an error.
<?php
$url = 'http://api.bitcoinvenezuela.com/DolarToday.php?json=yes';
$obj = json_decode(file_get_contents($url), true);
echo "<pre>";
print_r($obj);
?>
Regarding connection timeout you need to check IP block etc
It works fine for me.
I tested it on my webpage and it worked fine.
Just needed to replace echo with var_dump().
http://www.hoppvader.nu/Mail/test.php
$url = 'http://api.bitcoinvenezuela.com/DolarToday.php?json=yes';
$obj = json_decode(file_get_contents($url), true);
var_dump($obj);
To echo the two values you need you use this code:
echo $obj["_timestamp"]["epoch"];
echo $obj["USD"]["transferencia"];
Seems to be a connection problem on server side. Maybe there is some firewall configured or the server has no connection to the internet etc...
You should try the following, log in into server and try to run:
curl http://api.bitcoinvenezuela.com/DolarToday.php?json=yes
This command would basically try to reach the url and print the output.
If you have the same timeout issue here then you have the proof that the error is independent of your php script.
I am fairly new to php, and I have written code to work with the amazon API. When I request information from the API, I receive it, but am unable to sort through the XML. Here is the error:
Fatal error: Call to a member function children() on null in J:\XAMPP\htdocs\Phillip\src\MarketplaceWebServiceProducts\Samples\csv_prep.php on line 117
Here is the code:
if(is_array($xmlFiles)){
foreach($xmlFiles as $xmlFile){
$xml = simplexml_load_file($xmlFile);
foreach($xml->GetMatchingProductForIdResult as $items) {
//Line 117 ->
if(isset($items->Products->Product->AttributeSets->children('ns2', true)->ItemAttributes->ListPrice->Amount) !== False) {
$amount = $items->Products->Product->AttributeSets->children('ns2', true)->ItemAttributes->ListPrice->Amount
}else{
$amount = '0.00';
}
}
}
}
The tag in the XML that I am trying to get the value of looks like this:
<ns2:amount>9.99</ns2:amount>
It is in the same place as it says in the code. I only have this problem with large files and I am not sure what is happening. If someone could help, I would greatly appreciate it. Thanks in advance!
I'm not certain, but based on the error message, it looks like somewhere in the $items->Products->Product->AttributeSets hierarchy something you're specifying does not exist.
Do tests to see if $items or $items->Products or $items->Products->Product or $items->Products->Product->AttributeSets and whichever one fails, print out that fact and call exit;.
You could do a print_r on $items to help as well.
I am working with an API that has a "supported" library written by a third party.
I've done as the instructions say and feel I am very close to getting it working as it should however no matter what I try, (renaming, absolute paths, aggregated file paths, etc.) I'm getting the same error.
*I have an API key. This is not the issue
The error arises in this block:
define('API_KEY', ''); // //-- Insert your API key
define('PHP_SELF', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'));
require_once("FFN.class.php");
$ffn = new FFN(API_KEY); //where actual error is thrown
if (!API_KEY) {
echo 'You did not set the API_KEY for your application. This is required.';
exit;
}
And states:
PHP Fatal error: Class 'FFN' not found in /st/3/g/public_html/path/nerdapi.php on line 16
The actual error is thrown on $ffn = new FFN(API_KEY);
If anyone can spot my probably very obvious error, I'd really appreciate it.
Here is the site where I got the 3rd party code for the API's
https://github.com/philip/FantasyNerdAPI
i download the file, and put up these file:
FFN.class.php
sdk.php
on htdocs/a and accessing localhost/a/sdk.php
result was : You did not set the API_KEY for your application. This is required.
well, i didnt put the key.
i am having a code which parses the xml text which is obtained from google search
it used to working fine before , I think after updating my version infos it not working fine
what might be the problem i am getting the following error
Fatal error: Call to undefined method SimpleXMLElement::child_nodes() in /home/search.php in line 70
Please let me know how can i solve this problem
This code is used in smarty
And it gets the response string from curl.
SimpleXMLElement does not have a method called child_nodes. Were you looking for the children method?
okay many thanx for your answers .
i got solved my problem by using the domxml-php4-to-php5.php file i have just uploaded this file and included that file name in my file . And it got worked .
I got that file from this link : http://alexandre.alapetite.fr/doc-alex/domxml-php4-php5/
:)
use the following notation to iterate thru your xml (change 'myfile.xml' and 'tagName'):
<?php
include('simple_html_dom.php');
if (file_exists('myfile.xml')) {
$xml = simplexml_load_file('myfile.xml');
print_r($xml);
foreach( $xml->children() AS $child ) {
$name = $child->getName();
if ($name == 'tagName') {
foreach( $child->children() AS $grandchild ) {
// DO SOMETHING
}
}
}
}
?>
there are other more elegant ways to achieve this, but this is a simple beginner's way to do it. for technical info: http://us2.php.net/manual/en/class.simplexmlelement.php