Tag: url
<< Anterior
Siguiente >>
Twitter API PHP
// introduce aquí la descripción
Aqui esta mi API PHP, para que puedas conectarla con twitter. Esta super facil de usar ademas de tener algo de documentacion interior.
Tiene dependencias de XPath para PHP y libreria CURL.
Saludos
<?php /* Ejemplo de instancia */ require_once('class/twitter.class.php'); /* Metodo Constructor para Twitter */ $twitter = new Twitter('miusuario','mipass'); // Ejemplo :) echo "<h1>Todos los mensajes de Fayerwayer</h1>"; echo "<pre>"; echo "</pre>"; // Quieres realmente postear este mensaje? Descomentalo //$twitter->postearMensaje('Mi mensaje de pruebas desde API PHP para Twitter por framirez'); // Todos mis seguidores echo "<h1>Todos mis seguidores</h1>"; echo "<pre>"; echo "</pre>"; // Ahora quiero ver todos mis mensajes echo "<h1>Todos mis mensajes</h1>"; echo "<pre>"; foreach($twitter->lineaTiempo() as $mensajes): echo "<p>Mensaje: " . $mensajes['mensaje'] . " posteado a las " . $mensajes['hora'] . " desde " . $mensajes['desde'] ."</p>"; endforeach; echo "</pre>"; <?php /* @author: Fabian Ramirez Sepulveda @email : framirez(ARROB)gurunet.cl @web : http://www.gurunet.cl/framirez @desc: Proyecto para tener una API desde PHP mas accesible y facil para usuarios no avanzados. @metodos: lineaTiempo( $nickNameAmigo=opcional) - "Nos retorna todos los ultimos 10 mensajes que nuestro amigo o nosotros hemos posteado" tomarMensaje($idmensaje) - "Nos retorna el detalle completo del mensaje" postearMensaje($mensaje) - "Posteamos en tiempo real el mensaje desde PHP" seguidores() - "Nos retorna todos nuestros amigos que nos siguen" */ // Libreria necesaria para procesar Xpath require_once('XPath.class.php'); class Twitter { var $usuario=''; var $password=''; // Headers de nuestro cliente var $agente = 'Twitter PHP Class by framirez'; 'X-Twitter-Client-Version: 1.0', 'X-Twitter-Client-URL: http://www.gurunet.cl/framirez'); // Curl var $ch; // Respuesta var $respuesta; var $xml; function Twitter($usuario=null, $password=null) { $this->usuario = $usuario; $this->password = $password; // Metodo constructor automaticamente llama a Xpath $this->xml = new XPath(); } /* @desc: Retornamos el maximo de 10 mensajes de amigos o mios */ function lineaTiempo($nick = null) { $this->ch = curl_init("http://twitter.com/statuses/user_timeline.xml"); $this->xml->importFromString($this->setearOpcionesCurl()); else: $this->ch = curl_init("http://twitter.com/statuses/user_timeline/" . $nick . ".xml"); $this->xml->importFromString($this->setearOpcionesCurl()); endif; // Xpath Match $id = $this->xml->match('//id'); $nickname = $this->xml->match('//screen_name'); $texto = $this->xml->match('//text'); $hora = $this->xml->match('//created_at'); $desde = $this->xml->match('//location'); $deDonde = $this->xml->match('//source'); // Variables Temporales $i=0; // Recorro el arreglo for($i=0;$i<count($texto);$i++): $arregloMensajes[$i]['id'] = $this->xml->getData($id[$i]); $arregloMensajes[$i]['usuario'] = $this->xml->getData($nickname[$i]); $arregloMensajes[$i]['mensaje'] = $this->xml->getData($texto[$i]); $arregloMensajes[$i]['hora'] = $this->xml->getData($hora[$i]); $arregloMensajes[$i]['desde'] = $this->xml->getData($desde[$i]); $arregloMensajes[$i]['donde_proviene'] = $this->xml->getData($deDonde[$i]); $i++; endfor; $this->xml->reset(); return $arregloMensajes; } function tomarMensaje($id) { $this->ch = curl_init("http://twitter.com/statuses/user_timeline.xml"); $this->xml->importFromString($this->setearOpcionesCurl()); // Xpath Match $id = $this->xml->match('//id'); $nickname = $this->xml->match('//screen_name'); $texto = $this->xml->match('//text'); $hora = $this->xml->match('//created_at'); $desde = $this->xml->match('//location'); $deDonde = $this->xml->match('//source'); // Variables Temporales // Recorro el arreglo $arregloMensajes['id'] = $this->xml->getData($id[0]); $arregloMensajes['usuario'] = $this->xml->getData($nickname[0]); $arregloMensajes['mensaje'] = $this->xml->getData($texto[0]); $arregloMensajes['hora'] = $this->xml->getData($hora[0]); $arregloMensajes['desde'] = $this->xml->getData($desde[0]); $arregloMensajes['donde_proviene'] = $this->xml->getData($deDonde[0]); $this->xml->reset(); return $arregloMensajes; } function postearMensaje($mensaje) { else: $this->ch = curl_init("http://twitter.com/statuses/update.xml"); $this->xml->reset(); endif; return true; } function seguidores() { $this->ch = curl_init("http://twitter.com/statuses/followers.xml"); $this->xml->importFromString($this->setearOpcionesCurl()); // Xpath Match $id = $this->xml->match('//id'); $nickname = $this->xml->match('//screen_name'); $nombre = $this->xml->match('//name'); $desde = $this->xml->match('//location'); $web = $this->xml->match('//url'); $foto = $this->xml->match('//profile_image_url'); $descripcion = $this->xml->match('//description'); // Variables Temporales $i=0; // Recorro el arreglo for($i=0;$i<count($nickname);$i++): $arregloMensajes[$i]['id'] = $this->xml->getData($id[$i]); $arregloMensajes[$i]['nombre'] = $this->xml->getData($nombre[$i]); $arregloMensajes[$i]['desde'] = $this->xml->getData($desde[$i]); $arregloMensajes[$i]['usuario'] = $this->xml->getData($nickname[$i]); $arregloMensajes[$i]['web'] = $this->xml->getData($web[$i]); $arregloMensajes[$i]['foto'] = $this->xml->getData($foto[$i]); $arregloMensajes[$i]['descripcion'] = $this->xml->getData($descripcion[$i]); $i++; endfor; $this->xml->reset(); return $arregloMensajes; } function setearOpcionesCurl($post=false) { // Autentificamos curl_setopt($this->ch, CURLOPT_USERPWD, $this->usuario.':'.$this->password); curl_setopt($this->ch, CURLOPT_POST, true); curl_setopt($this->ch, CURLOPT_POSTFIELDS, $post); } curl_setopt($this->ch, CURLOPT_VERBOSE, 1); curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($this->ch, CURLOPT_USERAGENT, $this->agente); // Setamos la respuesta $respuesta = curl_exec($this->ch); curl_close($this->ch); return $respuesta; } } ?>
En PHP twitter php componente php5 curl xpath por framirez hace on 20/2/08 | Comentarios
Obtener encabezados de una dirección web
Devuelve las cabeceras de una dirección web
/** * function getHeaders (string $url, boolean $formato = true) * * Devuelve las cabeceras de una dirección web * Solo acepta HTTP como metodo * * Si $formato es true devuelve un array asociativo, * de lo contrario, un array de claves simples * * return array */ function getHeaders ($url, $formato = true) { return @get_headers($url, $formato); } return false; } $path = '/'; } else { $path = $partes['path']; } $path .= '?'.$partes['query']; } if (!$socket) { return false; } $header = 'HEAD '.$path.' HTTP/1.1'."\r\n" .'Connection: Close'."\r\n\r\n"; $fin = false; if ($header == "\r\n") { $fin = true; break; } else { } if ($formato == 1) { if ($key == $header) { $datos[] = $header; } else { } } else { $datos[] = $header; } } } return $datos; }
En PHP encabezados cabeceras url por Lito hace on 4/2/08 | Comentarios
Texto simple para URL
Cambia todo tipo de carácteres extraños por letras o símbolos equivalentes para poder usarlo como complemento en las URL's
/** * function palabra_simple (string $texto, boolean $min, boolean $html = false) * * Cambia las letras con tildes, eñes o caracteres raros por su concordancia natural. * En caso de que min sea true devolvera el texto en minúsculas. * * @$min: true/false para devolver el resultado en minúsculas * @$html: true/false si la cadena de texto que recibe está formateada con htmlentities * * return string */ function palabra_simple ($texto, $min = true, $html = false) { if (!$html) { } $texto = preg_replace(array('/[^a-z0-9_-]/i', '/-+/', '/^-/', '/-$/',), array('-', '-', '', ''), $texto); }
En PHP url texto simple por Lito hace on 4/2/08 | Comentarios
Descargar el contenido de una URL con cURL
function abrir($url) { $sesion = curl_init($url); curl_setopt($sesion, CURLOPT_RETURNTRANSFER, 1); curl_setopt($sesion, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($sesion, CURLOPT_TIMEOUT, 5); curl_setopt($sesion, CURLOPT_CONNECTTIMEOUT, 5); // Nos hacemos pasar por el Firefox curl_setopt($sesion, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; es-ES; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7'); $resultado = curl_exec($sesion); curl_close($sesion); return $resultado; }
En PHP curl por jape hace on 1/2/08 | Comentarios
Función para generar cadenas para URLs
Recibe una cadena de texto, por ejemplo el título de un artículo y lo convierte a un formáto válido para utilizarlo en URLs amigables.
function slug($slug) { $temp = ""; foreach ($slug as $token) { $temp .= $token." "; } return $slug; }
En PHP url friendly rewrite por admin hace on 30/1/08 | Comentarios
<< Anterior
Siguiente >>
