Ver Mensaje Individual
  #3 (permalink)  
Antiguo 09/03/2015, 03:15
Avatar de fbedia
fbedia
 
Fecha de Ingreso: julio-2010
Mensajes: 159
Antigüedad: 13 años, 9 meses
Puntos: 8
Respuesta: Steam Market: Lenguaje de respuesta (JSON)

Cita:
Iniciado por hhs Ver Mensaje
Investiga por Accept-Language HTTP header en google
Gracias por la respuesta.

Os dejo a continuación el codigo que tenia.. pueden probarlo tal cual esta en localhost o en un servidor:

Código PHP:
<?php
$url 
"http://steamcommunity.com/market/search/render/?l=espanish&start=0&count=20&currency=3&category_730_Weapon%5B%5D=tag_weapon_awp&appid=730&query=Man-o%27-war";
$json_objectfile_get_contents($url);
$json_decoded json_decode($json_object);


//precios
preg_match_all('/<span style="color:white">(.*)<\/span>/',$json_decoded->results_html$sor);

foreach(
$sor[1] as $k => $v)
{
    echo 
$v."<br/>";
}

?>
La respuesta que me arroja es:

Cita:
$29.34 USD
$33.62 USD
$111.90 USD
$80.00 USD
Como ven, los precios me los devuelve en $ dolares, cuando si abrimos la URL (http://steamcommunity.com/market/sea...y=Man-o%27-war) se muestran en español.

Investigue sobre lo que me comento hhs de Accept-Language HTTP header y añadi las siguientes lineas a mi codigo:

Código PHP:
<html lang="es">
<head>

<meta http-equiv="Content-Language" content="es"/>

</head>
<body>
<?php

$locale 
Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
echo 
$locale."<br/>";

$options = array(
  
'http'=>array(
    
'method'=>"GET",
    
'header'=>"Accept-language: es\r\n" 
              
"Cookie: foo=bar\r\n")
);

$context stream_context_create($options);

$url "http://steamcommunity.com/market/search/render/?l=espanish&start=0&count=20&currency=3&category_730_Weapon%5B%5D=tag_weapon_awp&appid=730&query=Man-o%27-war";
$json_objectfile_get_contents($url,false,$context);
$json_decoded json_decode($json_object);


//precios
preg_match_all('/<span style="color:white">(.*)<\/span>/',$json_decoded->results_html$sor);

foreach(
$sor[1] as $k => $v)
{
    echo 
$v."<br/>";
}

?>
</body>
</html>
Sin embargo, el resultado es que me sigue devolviendo resultados en $ Dolares.

Cita:
es_ES
$29.34 USD
$33.62 USD
$111.90 USD
$80.00 USD
¿Estoy haciendo algo mal?
¿Me falta algo?

Muchas gracias por su ayuda. Cualquier comentario o idea son bien recibidos!! Yo ya estoy desesperado con este tema y tengo la cabeza cerrada ya. Me ofusco cuando no entiendo las cosas ni encuentro una explicación a ellas...

Un saludo.
__________________
Follow me on twitter @franbedia