Foros del Web » Programando para Internet » Javascript »

Traer informacion desde un blog en variable JSON

Estas en el tema de Traer informacion desde un blog en variable JSON en el foro de Javascript en Foros del Web. buenas tardes queridos colegas del foro! Hoy me plnatee la tarea de mostrar los ultimos post de un blog (blogger/blogspot) Y bueno, hasta ahora lo ...
  #1 (permalink)  
Antiguo 11/04/2011, 15:08
Avatar de Heiroon  
Fecha de Ingreso: junio-2010
Ubicación: Caracas, Venezuela - Por ahora...
Mensajes: 495
Antigüedad: 13 años, 9 meses
Puntos: 63
Exclamación Traer informacion desde un blog en variable JSON

buenas tardes queridos colegas del foro!

Hoy me plnatee la tarea de mostrar los ultimos post de un blog (blogger/blogspot)

Y bueno, hasta ahora lo he logrado.. ahora, el problema esta en que no se como traer la imagen del post y es lo unico que me falta!

aun me cuesta entender un poco como trabaja la funciona la funcion pero ahi vamos... aca se las dejo para ver si me pueden ayudar...

La pregunta en concreto es, Que debo hacer para ahora traer la imagen del post.. cualquier info que necesiten me dicen! Gracias de antemano!!!

Código Javascript:
Ver original
  1. function showrecentposts(json) {
  2.  
  3.   for (var i = 0; i < numposts; i++) {
  4.     var entry = json.feed.entry[i];
  5.     var posttitle = entry.title.$t;
  6.     var posturl;
  7.     if (i == json.feed.entry.length) break;
  8.     for (var k = 0; k < entry.link.length; k++) {
  9.       if (entry.link[k].rel == 'alternate') {
  10.         posturl = entry.link[k].href;
  11.         break;
  12.       }
  13.     }
  14.     posttitle = posttitle.link(posturl);
  15.     var readmorelink = "Leer M\xE1s";
  16.     readmorelink = readmorelink.link(posturl);
  17.     var postdate = entry.published.$t;
  18.     var cdyear = postdate.substring(0,4);
  19.     var cdmonth = postdate.substring(5,7);
  20.     var cdday = postdate.substring(8,10);
  21.     var monthnames = new Array();
  22.     monthnames[1] = "Ene";
  23.     monthnames[2] = "Feb";
  24.     monthnames[3] = "Mar";
  25.     monthnames[4] = "Abr";
  26.     monthnames[5] = "May";
  27.     monthnames[6] = "Jun";
  28.     monthnames[7] = "Jul";
  29.     monthnames[8] = "Ago";
  30.     monthnames[9] = "Sep";
  31.     monthnames[10] = "Oct";
  32.     monthnames[11] = "Nov";
  33.     monthnames[12] = "Dic";
  34.     if ("content" in entry) {
  35.       var postcontent = entry.content.$t;}
  36.     else
  37.     if ("summary" in entry) {
  38.       var postcontent = '<p class=\'titulo\'>' + entry + '</p>'.summary.$t;}
  39.     else var postcontent = "";
  40.     var re = /<\S[^>]*>/g;
  41.     document.write('<div class=\'bloq_not\' style=\'border-bottom:1px #CCCCCC solid\'>');
  42.     postcontent = postcontent.replace(re, "");
  43.     if (!standardstyling) document.write('<div class="bbrecpost">');
  44.     if (standardstyling) document.write('<br/>');
  45.     document.write(posttitle);
  46.    
  47.     if (!standardstyling) document.write('</div><div class="bbrecpostsum"><p>');
  48.     if (showpostsummary == true) {
  49.       if (standardstyling) document.write('<br/>');
  50.       if (postcontent.length < numchars) {
  51.          if (standardstyling) document.write('<i>');
  52.          document.write(postcontent);
  53.          if (standardstyling) document.write('</i>');}
  54.       else {
  55.          if (standardstyling) document.write('<i>');
  56.          postcontent = postcontent.substring(0, numchars);
  57.          var quoteEnd = postcontent.lastIndexOf(" ");
  58.          postcontent = postcontent.substring(0,quoteEnd);
  59.          document.write(postcontent + '...' );
  60.          if (showpostdate == true) document.write('<div>' + readmorelink +' <br/> <span>' + cdday + ' ' + monthnames[parseInt(cdmonth,10)] + '</span></div></div>');
  61.          if (standardstyling) document.write('</i>');}
  62. }
  63.     if (!standardstyling) document.write('</p></div>');
  64.     if (standardstyling) document.write('<br/>');
  65. }
  66. if (!standardstyling) document.write('<div class="bbwidgetfooter">');
  67. if (standardstyling) document.write('<br/>');
  68. //document.write('<span style="font-size:80%;">Widget by <a href="http://beautifulbeta.blogspot.com">Beautiful Beta</a></span>');
  69. document.write('</div>');
  70.  
  71.  
  72. }
__________________
Gmail : [email protected]
Twitter: @heiroon

I'm back!
  #2 (permalink)  
Antiguo 11/04/2011, 15:16
Avatar de Heiroon  
Fecha de Ingreso: junio-2010
Ubicación: Caracas, Venezuela - Por ahora...
Mensajes: 495
Antigüedad: 13 años, 9 meses
Puntos: 63
Respuesta: Traer informacion desde un blog en variable JSON

disculpen! me falto poner la parte donde se llama la funcion:

ahi es de donde no se como determinar si con el llamado que se hace viene dentro de la variable entry la imagen del post tambien... es que nunca he trabajado con variables JSON..

bueno aca esta...

Código Javascript:
Ver original
  1. <script src="scripts/showrecentposts_es.js" type="text/javascript">
  2. </script>
  3. <script language="javascript">
  4. var numposts = 2;
  5. var numchars = 210;
  6. var showpostdate = true;
  7. var showpostsummary = true;
  8. var standardstyling = false;
  9. </script>
  10. <script src="http://corinproinca.blogspot.com/feeds/posts/default?orderby=published&alt=json-in-script&callback=showrecentposts"></script>
__________________
Gmail : [email protected]
Twitter: @heiroon

I'm back!
  #3 (permalink)  
Antiguo 12/04/2011, 11:07
Avatar de Heiroon  
Fecha de Ingreso: junio-2010
Ubicación: Caracas, Venezuela - Por ahora...
Mensajes: 495
Antigüedad: 13 años, 9 meses
Puntos: 63
De acuerdo Respuesta: Traer informacion desde un blog en variable JSON

Me respondo yo mismo:

Aca logre hacer lo que queria, muestro los ultimos posts de un blogger con imagen, fecha y descripcion.

Para el que lo necesite:

Código Javascript:
Ver original
  1. function showrecentposts(json) {
  2.    
  3.     var ObjetoJSON = json;
  4.     console.log(ObjetoJSON);
  5.    
  6.   for (var i = 0; i < numposts; i++) {
  7.     var entry = json.feed.entry[i];
  8.     var posttitle = entry.title.$t;
  9.     var posturl;
  10.     if (i == json.feed.entry.length) break;
  11.     for (var k = 0; k < entry.link.length; k++) {
  12.       if (entry.link[k].rel == 'alternate') {
  13.         posturl = entry.link[k].href;
  14.         break;
  15.       }
  16.     }
  17.     var postimage = entry.media$thumbnail.url;
  18.    
  19.     posttitle = posttitle.link(posturl);
  20.     var readmorelink = "Leer Art\xEDculo";
  21.     readmorelink = readmorelink.link(posturl);
  22.     var postdate = entry.published.$t;
  23.     var cdyear = postdate.substring(0,4);
  24.     var cdmonth = postdate.substring(5,7);
  25.     var cdday = postdate.substring(8,10);
  26.     var monthnames = new Array();
  27.     monthnames[1] = "Ene";
  28.     monthnames[2] = "Feb";
  29.     monthnames[3] = "Mar";
  30.     monthnames[4] = "Abr";
  31.     monthnames[5] = "May";
  32.     monthnames[6] = "Jun";
  33.     monthnames[7] = "Jul";
  34.     monthnames[8] = "Ago";
  35.     monthnames[9] = "Sep";
  36.     monthnames[10] = "Oct";
  37.     monthnames[11] = "Nov";
  38.     monthnames[12] = "Dic";
  39.     if ("content" in entry) {
  40.       var postcontent = entry.content.$t;}
  41.     else
  42.     if ("summary" in entry) {
  43.        
  44.       var postcontent = '<p class=\'titulo\'>' + entry.summary.$t + '</p>';}
  45.     else var postcontent = "";
  46.     var re = /<\S[^>]*>/g;
  47.     document.write('<div class=\'bloq_not\' style=\'border-bottom:1px #CCCCCC solid\'>');
  48.     postimage = postimage.replace(/s72-c/g, 's400');
  49.     document.write('<img src="' + postimage + '" width="254" height="104" alt="noticia secundaria" />');
  50.     postcontent = postcontent.replace(re, "");
  51.     if (!standardstyling) document.write('<div class="bbrecpost">');
  52.     if (standardstyling) document.write('<br/>');
  53.     document.write(posttitle);
  54.    
  55.     if (!standardstyling) document.write('</div><div class="bbrecpostsum"><p>');
  56.     if (showpostsummary == true) {
  57.       if (standardstyling) document.write('<br/>');
  58.       if (postcontent.length < numchars) {
  59.          if (standardstyling) document.write('<i>');
  60.          document.write(postcontent);
  61.          if (standardstyling) document.write('</i>');}
  62.       else {
  63.          if (standardstyling) document.write('<i>');
  64.          postcontent = postcontent.substring(0, numchars);
  65.          var quoteEnd = postcontent.lastIndexOf(" ");
  66.          postcontent = postcontent.substring(0,quoteEnd);
  67.          document.write(postcontent + '...' );
  68.          if (showpostdate == true) document.write('<div>' + readmorelink +' <br/> <span>' + cdday + ' ' + monthnames[parseInt(cdmonth,10)] + '</span></div></div>');
  69.          if (standardstyling) document.write('</i>');}
  70. }
  71.     if (!standardstyling) document.write('</p></div>');
  72.     if (standardstyling) document.write('<br/>');
  73. }
  74. if (!standardstyling) document.write('<div class="bbwidgetfooter">');
  75. if (standardstyling) document.write('<br/>');
  76. //document.write('<span style="font-size:80%;">Widget by <a href="http://beautifulbeta.blogspot.com">Beautiful Beta</a></span>');
  77. document.write('</div>');
  78.  
  79.  
  80. }
__________________
Gmail : [email protected]
Twitter: @heiroon

I'm back!
  #4 (permalink)  
Antiguo 21/05/2011, 00:59
 
Fecha de Ingreso: marzo-2011
Mensajes: 3
Antigüedad: 13 años
Puntos: 0
Respuesta: Traer informacion desde un blog en variable JSON

Gracias.

Pero sabes como mostrar todas las entradas del blog?

por ejemplo con:

Código PHP:
json.feed.entry.length 
muestras la cantidadde entradas pero del feed, que creo son 25 en mi caso, pero tengo en total 52 entradas.

Sabes como hacer para sacar el total de todas las entradas?

Saludos!!

Etiquetas: feed, informacion, json, bloggers
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta

SíEste tema le ha gustado a 1 personas




La zona horaria es GMT -6. Ahora son las 02:58.