<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Enrique Chávez Garcia- Desarrollo de Web &#187; PHP</title>
	<atom:link href="http://tmeister.net/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://tmeister.net</link>
	<description>Blog acerca de desarrollo orientado hacia Flash, Flex y Actionscript.</description>
	<lastBuildDate>Thu, 19 Jan 2012 20:25:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Obtener tweets usando PHP &amp; Flex 4 (Gumbo)</title>
		<link>http://tmeister.net/2009/12/09/obtener-tweets-usando-php-flex-4-gumbo/</link>
		<comments>http://tmeister.net/2009/12/09/obtener-tweets-usando-php-flex-4-gumbo/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 23:17:49 +0000</pubDate>
		<dc:creator>Tmeister</dc:creator>
				<category><![CDATA[Flex 4]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[api ejemplo]]></category>

		<guid isPermaLink="false">http://tmeister.net/?p=512</guid>
		<description><![CDATA[En este ejemplo, ya no muy básico, les mostrare como obtener los últimos tweets de un usuario y mostrarlos en Flex 4 (Gumbo) para ello haremos uso de PHP como gateway, con PHP obtendremos los tweets por medio del API de Twitter y los desplegaremos en forma de XML para poder leerlos en Flex. Este ejemplo esta hecho [...]]]></description>
			<content:encoded><![CDATA[<p>En este <a href="http://tmeister.net/category/flex-4/">ejemplo</a>, ya no muy básico, les mostrare como obtener los últimos tweets de un usuario y mostrarlos en <a href="http://tmeister.net/category/flex-4/">Flex 4 (Gumbo)</a> para ello haremos uso de PHP como gateway, con PHP obtendremos los tweets por medio del <a href="http://apiwiki.twitter.com/">API de Twitter</a> y los desplegaremos en forma de XML para poder leerlos en Flex.</p>
<div class="info">Este ejemplo esta hecho con <a href="http://labs.adobe.com/technologies/flashbuilder4/" target="_blank">Flash Builder 4 Beta 2</a> y necesita el <a href="https://www.adobe.com/go/getflashplayer">FlashPlayer 10</a> para poder visualizarlo correctamente</div>
<h1>Ejemplo</h1>
<div>
<object width="600" height="350">
<param name="movie" value="http://tmeister.net/flex/gumbo/last-tweet/tweets.swf"></param>
<param name="quality" value="high"></param>
<param name="wmode" value="transparent"></param>
<param name="menu" value="false"></param>
<param name="bgcolor" value="#ffffff"></param>
<param name="allowScriptAccess" value="always"></param>
<param name="allowFullScreen" value="true"></param>
<embed type="application/x-shockwave-flash" width="600" height="350" src="http://tmeister.net/flex/gumbo/last-tweet/tweets.swf" quality="high" bgcolor="#ffffff" wmode="transparent" menu="false" allowFullScreen="true" ></embed>
</object>
</div>
<p>Lo primero que necesitamos es crear el script en PHP para poder conectarnos al <a href="http://apiwiki.twitter.com/">API de Twitter</a>, obtener los tweets y desplegarlos en XML.</p>
<h1>PHP</h1>
<pre class="brush: php; title: ; notranslate">
&lt;?php
/**
 * get_user_tweets()
 *
 * @param mixed $username
 * @param integer $count
 * @return array $out
 */
function get_user_tweets($username, $count = 10)
{
	/**
	 * URL para obtener los tweets en formato JSON
	 * Utilizaremos curl para hacer la conexion al API de Twitter
	 * */
	$url = 'http://twitter.com/statuses/user_timeline/'.$username.'.json?count='.$count;
	$curl = curl_init();

	/**
	 * Iniciamos CURL pasando que URL vamos a cargar
	 * */
	curl_setopt($curl, CURLOPT_URL, $url);
	/**
	 * Indicamos que querremos el output de regreso
	 * */
	curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
	/**
	 * Ponemos un TimeOut al script
	 */
	curl_setopt ($curl, CURLOPT_CONNECTTIMEOUT, 10);

	/**
	 * Ejecutamos CURL
	 */
	$json = curl_exec($curl);

	/**
	 * Cerramos la conexion
	 */
	curl_close($curl);

	/**
	 * Tomanos el resultado (JSON) y lo parseamos en PHP
	 */
	$tweets = json_decode($json);
	$out;

	/**
	 * Por ultimo por cada tweet tomanos el contenido y lo metemos en un Array
	 */
	foreach($tweets as $tweet)
	{
		$out[] = $tweet-&gt;text;
	}

	return $out;
}

/**
 * Con la informacion obtenida del API construimos un XML y lo mostramos
 */
$out = '&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf8&quot;?&gt;';
$out .= &quot;&lt;tweets&gt;&quot;;
$tweets = get_user_tweets('tmeister', 10);
foreach($tweets as $tweet)
{
	$out .= &quot;&lt;tweet&gt;$tweet&lt;/tweet&gt;&quot;;
}
$out .= &quot;&lt;/tweets&gt;&quot;;
header (&quot;content-type: text/xml&quot;);
echo $out;
?&gt;
</pre>
<p>El resultado del script lo puedes ver en <a href="http://tmeister.net/flex/gumbo/last-tweet/last.php">http://tmeister.net/flex/gumbo/last-tweet/last.php</a></p>
<h1>MXML</h1>
<p>Una vez que tenemos el XML solo falta mostrar su contenido en Flex.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application
    xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
    xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;
    xmlns:mx=&quot;library://ns.adobe.com/flex/halo&quot;
    width=&quot;100%&quot;
    height=&quot;100%&quot;
    creationComplete=&quot;{service.send()}&quot;
    viewSourceURL=&quot;http://tmeister.net/flex/gumbo/last-tweet/srcview/index.html&quot;
    &gt;

    &lt;fx:Script&gt;
        &lt;![CDATA[
            import mx.collections.ArrayCollection;
            import mx.controls.Alert;
            import mx.rpc.events.FaultEvent;
            import mx.rpc.events.ResultEvent;

            [Bindable]
            private var _tweets:ArrayCollection;

            protected function service_resultHandler(event:ResultEvent):void
            {

                _tweets = new ArrayCollection();

                for each( var tweet:String in event.result.tweet  )
                {
                    _tweets.addItem(tweet);
                }
            }

            protected function service_faultHandler(event:FaultEvent):void
            {
                Alert.show(event.fault.faultString, &quot;Error&quot;);
            }

        ]]&gt;
    &lt;/fx:Script&gt;

    &lt;fx:Declarations&gt;
        &lt;s:HTTPService
            id=&quot;service&quot;
            result=&quot;service_resultHandler(event)&quot;
            fault=&quot;service_faultHandler(event)&quot;
            url=&quot;http://tmeister.net/flex/gumbo/last-tweet/last.php&quot;
            showBusyCursor=&quot;true&quot;
            resultFormat=&quot;e4x&quot;
            &gt;
        &lt;/s:HTTPService&gt;
    &lt;/fx:Declarations&gt;

    &lt;mx:VBox verticalCenter=&quot;0&quot; horizontalCenter=&quot;0&quot;&gt;
        &lt;mx:Repeater id=&quot;rep&quot; dataProvider=&quot;{_tweets}&quot;&gt;
            &lt;s:Label text=&quot;{rep.currentItem}&quot; /&gt;
            &lt;mx:HRule width=&quot;100%&quot; /&gt;
        &lt;/mx:Repeater&gt;
    &lt;/mx:VBox&gt;

&lt;/s:Application&gt;
</pre>
<p>Con esto ya podemos mostrar los últimos tweets de un timeline sin necesidad de usar librerias ni de PHP o de ActionScript.</p>
]]></content:encoded>
			<wfw:commentRss>http://tmeister.net/2009/12/09/obtener-tweets-usando-php-flex-4-gumbo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Object Caching 388/405 objects using disk: basic

Served from: tmeister.net @ 2012-02-06 23:54:02 -->

<!-- W3 Total Cache: Db cache debug info:
Engine:             disk: basic
Total queries:      16
Cached queries:     1
Total query time:   0.0427
SQL info:
    # | Time (s) |    Caching (Reject reason)     |   Status   | Data size (b) | Query
    1 |   0.0063 |  disabled (Query is rejected)  | not cached |             0 | SELECT option_name, option_value FROM wp_options WHERE autoload = 'yes'
    2 |   0.0009 |  disabled (Query is rejected)  | not cached |             0 | SHOW TABLES LIKE 'wp_tla_data'
    3 |   0.0017 |  disabled (Query is rejected)  | not cached |             0 | SHOW COLUMNS FROM wp_tla_data LIKE 'xml_key'
    4 |   0.0232 |            enabled             | not cached |          4215 | SELECT * FROM wp_tla_data
    5 |   0.0002 |            enabled             | not cached |           714 | SELECT post_modified_gmt FROM wp_posts WHERE post_status = 'publish' AND post_type IN ('post', 'page', 'attachment', 'slideshow', 'portfolio') ORDER BY post_modified_gmt DESC LIMIT 1
    6 |   0.0001 |            enabled             | not cached |           698 | SELECT post_date_gmt FROM wp_posts WHERE post_status = 'publish' AND post_type IN ('post', 'page', 'attachment', 'slideshow', 'portfolio') ORDER BY post_date_gmt DESC LIMIT 1
    7 |   0.0005 |            enabled             | not cached |           672 | SELECT wp_term_taxonomy.term_id
					FROM wp_term_taxonomy
					INNER JOIN wp_terms USING (term_id)
					WHERE taxonomy = 'category'
					AND wp_terms.slug IN ('php')
    8 |   0.0003 |            enabled             | not cached |           634 | SELECT term_taxonomy_id
					FROM wp_term_taxonomy
					WHERE taxonomy = 'category'
					AND term_id IN (60)
    9 |   0.0003 |            enabled             | not cached |          3450 | SELECT t.*, tt.* FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = 'category' AND t.slug = 'php' LIMIT 1
   10 |   0.0012 |  disabled (Query is rejected)  | not cached |             0 | SELECT SQL_CALC_FOUND_ROWS  wp_posts.* FROM wp_posts  INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1  AND ( wp_term_relationships.term_taxonomy_id IN (73) ) AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 15
   11 |   0.0049 |  disabled (Query is rejected)  | not cached |             0 | SELECT FOUND_ROWS()
   12 |   0.0003 |            enabled             |   cached   |          3450 | SELECT t.*, tt.* FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = 'category' AND t.slug = 'php' LIMIT 1
   13 |   0.0011 |            enabled             | not cached |          4058 | SELECT t.*, tt.* FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('category') AND tr.object_id IN (512) ORDER BY t.name ASC
   14 |   0.0008 |            enabled             | not cached |          4078 | SELECT t.*, tt.* FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('post_tag') AND tr.object_id IN (512) ORDER BY t.name ASC
   15 |   0.0004 |            enabled             | not cached |          1814 | SELECT post_id, meta_key, meta_value FROM wp_postmeta WHERE post_id IN (512)
   16 |   0.0005 |            enabled             | not cached |         14100 | SELECT * FROM wp_posts WHERE ID = 512 LIMIT 1
-->

<!-- W3 Total Cache: Page cache debug info:
Engine:             disk: enhanced
Cache key:          category/php/feed/_index.html
Caching:            disabled
Reject reason:      DONOTCACHEPAGE constant is defined
Status:             not cached
Creation Time:      0.674s
Header info:
X-Pingback:         http://tmeister.net/xmlrpc.php
Last-Modified:      Thu, 19 Jan 2012 20:25:41 GMT
ETag:               "5128b61493d147f8e15e42f284d2c6d2"
X-Powered-By:       W3 Total Cache/0.9.2.4
Content-Type:       text/xml; charset=utf-8
-->
