Ver Mensaje Individual
  #5 (permalink)  
Antiguo 05/01/2012, 20:48
Alex265
 
Fecha de Ingreso: mayo-2011
Mensajes: 65
Antigüedad: 13 años
Puntos: 3
Respuesta: Recoger datos de un foro

Nada, de verdad que no lo entiendo. Para practicar he cogido la web de twitter y he intentado sacar el contenido de los últimos tweets de la gente a la que sigo, mostrando prácticamente mi página de twitter en el navegador con cURL. He habilitado cURL y he usado lo siguiente:

Código PHP:
Ver original
  1. <?php  
  2.         $cookie_file_path = "c:/cookiefile";//o lo que sea
  3. $LOGINURL = "http://www.twitter.com";
  4. $agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";
  5. $POSTFIELDS = 'session[username_or_email]=USUARIO&session[password]=CONTRASEÑA';
  6. //donde session[username_or_email] es el name del input del campo usuario
  7. //y session[password] es el name input del campo contraseña.
  8.  
  9. $ch = curl_init();
  10. curl_setopt($ch, CURLOPT_URL,$LOGINURL);
  11. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
  12. curl_setopt($ch, CURLOPT_USERAGENT, $agent);
  13. curl_setopt($ch, CURLOPT_POST, 1);
  14. curl_setopt($ch, CURLOPT_POSTFIELDS,$POSTFIELDS);
  15. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  16. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  17. curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
  18. curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
  19. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  20. $page = curl_exec ($ch);
  21. curl_close ($ch);
  22. echo $page;
  23.     ?>

Es la primera vez que me manejo con cURL y no sé si el código tal cual está ahí debería servir (según he leido en el tema que me has aportado debería funcionar. Pero me muestra la web principal de twitter como si no me hubiera conectado. Le estoy dando vueltas pero no consigo hacerlo funcionar.

Gracias.