daily pastebin goal
87%
SHARE
TWEET

twitter lib 2.0

diabliyo Mar 5th, 2012 63 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. <?php
  2. # Twitter Lib v2.0
  3. # M.S.I Angel Cantu Jauregui
  4. # angel.cantu@sie-group.net
  5. # Date Mar 5, 2012 10:44
  6.  
  7. define( TWITTER_API_SERVER, "api.twitter.com" ); # servidor seguro api
  8. define( TWITTER_API_REQUEST_TOKEN, "/oauth/request_token" ); # servidor seguro api request token
  9. define( TWITTER_AUTENTICACION_URL, "/oauth/authenticate" ); # URL de autenticacion inicial  
  10. define( TWITTER_API_AUTORIZACION, "/oauth/authorize" ); # servidor seguro api autorizacion
  11. define( TWITTER_API_ACCESS_TOKEN, "/oauth/access_token" ); # servidor seguro api access token
  12.  
  13. # variables tu APP
  14. define( TWITTER_KEY, "MI_KEY" ); # tu key
  15. define( TWITTER_SECRET, "MI_SECRET" ); # key secret
  16. define( TWITTER_CALLBACK, "MI_URL_" ); # tu callback
  17.  
  18. function rfc3986_encode($string)  
  19.         {  
  20.         $result = rawurlencode($string);  
  21.         $result = str_replace('%7E', '~', $result);  
  22.         $result = str_replace('=', '%3D', $result);  
  23.         $result = str_replace('+', '%2B', $result);  
  24.         return $result;  
  25.         }  
  26.  
  27. function twitter_geturl_loginout()
  28.         {
  29.         if( ! ($rqtoken= twitter_request_token()) ) # consultamos por una token
  30.                 echo '...Error';
  31.         else            print_r($rqtoken);
  32.         }
  33.        
  34. function twitter_get_nonce($tiempo)
  35.         {
  36.         return md5($tiempo); # md5s look nicer than numbers
  37.         }
  38.  
  39. function twitter_encodedata( $buf, $delimiter, $aux )
  40.         {
  41.         $data=''; # buffer
  42.         foreach( $buf as $key=>$val ) # ciclo
  43.                 {
  44.                 if( $data )
  45.                         {
  46.                         $data .= $delimiter; # si tiene datos, ponemos delimitador
  47.                         if( $aux )              $data .= "\r\n";
  48.                         }
  49.                 $data .= $key. "=";
  50.                
  51.                 if( $aux )              $data .= $val; # concatenamos
  52.                 else            $data .= "\"". rfc3986_encode($val). "\"";
  53.                 }
  54.         return $data; # retornamos
  55.         }
  56.  
  57. function twitter_get_signature( $data, $m )
  58.         {
  59.         if( !is_array($data) )          return 0;
  60.        
  61.         $buf= $m[0].'&'. rfc3986_encode( 'https://'. TWITTER_API_SERVER.$m[2]).'&'.twitter_encodedata($data, ',', 0); # obtiene string delimitada por comas y encodeada
  62.         $keys= rfc3986_encode(TWITTER_SECRET). '&'. rfc3986_encode($m[1]);
  63.         echo '<br><h1>Base String</h1><br>'. $buf;
  64.         $crypt= base64_encode( hash_hmac( 'sha1', $buf, $keys, true ) );
  65.         unset($buf, $keys);
  66.         return $crypt;
  67.         }
  68.  
  69. # obtiene autenticacion para la APP primra vez
  70. function twitter_get_autenticacion()
  71.         {
  72.         $a= socket_iodata( TWITTER_API_SERVER, array( 'GET', TWITTER_AUTENTICACION_URL ), 443 );
  73.         return $a;
  74.         }
  75.  
  76. # obtener una request token
  77. function twitter_request_token( $metodo )
  78.         {
  79.         $tiempo= time();
  80.         $oauthmsg= array( "oauth_callback"=>"". TWITTER_CALLBACK. "",
  81.                                                                 "oauth_consumer_key"=>"". TWITTER_KEY. "",
  82.                                                                 "oauth_nonce"=>"". twitter_get_nonce($tiempo). "",
  83.                                                                 "oauth_signature_method"=>"HMAC-SHA1",
  84.                                                                 "oauth_timestamp"=>"". $tiempo. "",
  85.                                                                 "oauth_version"=>"1.0" );
  86.  
  87.         $firma= twitter_get_signature($oauthmsg, array('POST', '', TWITTER_API_REQUEST_TOKEN) ); # creamos firma apartir de array
  88.         if( !$firma )
  89.                 return 'Error: Generar Firma';
  90.         $oauthmsg["oauth_signature"]="". $firma. "";
  91.        
  92.         if( !strcmp($metodo, "socket") ) # socket
  93.                 $rqtoken= socket_iodata( TWITTER_API_SERVER, array( 'POST', TWITTER_API_REQUEST_TOKEN, twitter_encodedata($oauthmsg, ',', 0), 'oauth' ), 443 );
  94.         else            $rqtoken= curl_iodata( TWITTER_API_SERVER, array( 'POST', TWITTER_API_REQUEST_TOKEN, twitter_encodedata($oauthmsg, ',', 0), 'oauth' ), 443 ); # curl
  95.         unset($oauthmsg);
  96.  
  97.         #if( $rqtoken==-1 )
  98.         #       {
  99.         #       echo 'Error Socket Connection';
  100.         #       return 0;
  101.         #       }
  102.         #else if( !$rqtoken )
  103.         #       {
  104.         #       echo 'Error No Data in Oauth Request: '. $rqtoken;
  105.         #       return 0;
  106.         #       }
  107.                
  108.         return $rqtoken;
  109.         }
  110.  
  111. # obtener una request token
  112. function twitter_access_token( $metodo )
  113.         {
  114.         $tiempo= time();
  115.         $oauthmsg= array( "oauth_callback"=>"". TWITTER_CALLBACK. "",
  116.                                                                 "oauth_consumer_key"=>"". TWITTER_KEY. "",
  117.                                                                 "oauth_nonce"=>"". twitter_get_nonce($tiempo). "",
  118.                                                                 "oauth_signature_method"=>"HMAC-SHA1",
  119.                                                                 "oauth_timestamp"=>"". $tiempo. "",
  120.                                                                  "oauth_version"=>"1.0" );
  121.                                                                  #"x_auth_mode"=>"client_auth",
  122.                                                                  #"x_auth_password"=>"twitter-xauth",
  123.                                                                  #"x_auth_username"=>"oauth_test_exec" );
  124.                                                                  
  125.         #$post_data= array( "x_auth_mode"=>"client_auth",
  126.         #                                                        "x_auth_password"=>"twitter-xauth",
  127.         #                                                        "x_auth_username"=>"oauth_test_exec" );
  128.  
  129.         $firma= twitter_get_signature($oauthmsg, array('POST', '', TWITTER_API_ACCESS_TOKEN) ); # creamos firma apartir de array
  130.         if( !$firma )
  131.                 return 'Error: Generar Firma';
  132.         $oauthmsg["oauth_signature"]="". $firma. "";
  133.        
  134.         # twitter_encodedata($post_data, '&', 0)
  135.         if( !strcmp($metodo, "socket") ) # socket
  136.                 $rqtoken= socket_iodata( TWITTER_API_SERVER, array( 'POST', TWITTER_API_ACCESS_TOKEN, twitter_encodedata($oauthmsg, ',', 1), 'oauth' ), 443 );
  137.         else            $rqtoken= curl_iodata( TWITTER_API_SERVER, array( 'POST', TWITTER_API_ACCESS_TOKEN, twitter_encodedata($oauthmsg, ',', 1), 'oauth' ), 443 ); # curl
  138.         unset($oauthmsg);
  139.  
  140.         #if( $rqtoken==-1 )
  141.         #       {
  142.         #       echo 'Error Socket Connection';
  143.         #       return 0;
  144.         #       }
  145.         #else if( !$rqtoken )
  146.         #       {
  147.         #       echo 'Error No Data in Oauth Request: '. $rqtoken;
  148.         #       return 0;
  149.         #       }
  150.                
  151.         return $rqtoken;
  152.         }
  153.  
  154. function twitter_boxsearch()
  155.         {
  156. return '<script charset="utf-8" src="http://widgets.twimg.com/j/2/widget.js"></script>
  157. <script>
  158. new TWTR.Widget({
  159.  version: 2,
  160.  type: \'search\',
  161.  search: \'turundus reynosa\',
  162.  interval: 30000,
  163.  title: \'Turunderos en...\',
  164.  subject: \'Reynosa\',
  165.  width: 175,
  166.  height: 350,
  167.  theme: {
  168.    shell: {
  169.      background: \'#8ec1da\',
  170.      color: \'#ffffff\'
  171.    },
  172.    tweets: {
  173.      background: \'#ffffff\',
  174.      color: \'#444444\',
  175.      links: \'#1985b5\'
  176.    }
  177.  },
  178.  features: {
  179.    scrollbar: true,
  180.    loop: true,
  181.    live: true,
  182.    behavior: \'default\'
  183.  }
  184. }).render().start();
  185. </script>';
  186.         }
  187.  
  188.  
  189. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Pastebin PRO 'CHRISTMAS SPECIAL'!
Get 60% OFF Pastebin PRO accounts!
 
Top