Twitter para FWH

Twitter para FWH

Postby Antonio Linares » Tue Feb 12, 2013 12:46 pm

Estos son los primeros pasos hacia la construcción de una Clase Twitter para FWH basada en Curl :-)

Nos basamos en este ejemplo:
http://www.barattalo.it/2010/09/09/how-to-change-twitter-status-with-php-and-curl-without-oauth/

y usamos la libreria curl para Harbour disponible desde aqui:
http://code.google.com/p/harbour-and-xharbour-builds/downloads/detail?name=hbcurl.zip&can=2&q=

Primera prueba:
Code: Select all  Expand view
#include "FiveWin.ch"
#include "hbcurl.ch"

function Main()

   local hCurl, cPage := Space( 200 )

   curl_global_init()

   if ! Empty( hCurl := curl_easy_init() )
      curl_easy_setopt( hCurl, HB_CURLOPT_URL, "https://mobile.twitter.com/session/new" )
      curl_easy_setopt( hCurl, HB_CURLOPT_SSL_VERIFYPEER, .F. )
      curl_easy_setopt( hCurl, HB_CURLOPT_FAILONERROR, 1 )
      curl_easy_setopt( hCurl, HB_CURLOPT_FOLLOWLOCATION, 1 )
      // curl_easy_setopt( hCurl, HB_CURLOPT_RETURNTRANSFER, 1 )
      curl_easy_setopt( hCurl, HB_CURLOPT_TIMEOUT, 5 )
      curl_easy_setopt( hCurl, HB_CURLOPT_COOKIEJAR, "my_cookies.txt" )
      curl_easy_setopt( hCurl, HB_CURLOPT_COOKIEFILE, "my_cookies.txt" )
      curl_easy_setopt( hCurl, HB_CURLOPT_USERAGENT, "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3 " )
        curl_easy_setopt( hCurl, HB_CURLOPT_ERRORBUFFER, @cPage )
       
        MsgInfo( curl_easy_perform( hCurl ) )
      MsgInfo( curl_easy_dl_buff_get( hCurl ) )
       
      curl_easy_reset( hCurl )
   endif

   curl_global_cleanup()

return nil


Necesitamos localizar el valor del define CURLOPT_RETURNTRANSFER. No esta disponible dentro de hbcurl.ch de Harbour
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42052
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Twitter para FWH

Postby Antonio Linares » Tue Feb 12, 2013 12:55 pm

Encontrado :-)

#define HB_CURLOPT_RETURNTRANSFER 500
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42052
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Twitter para FWH

Postby Antonio Linares » Tue Feb 12, 2013 1:27 pm

Esta versión recupera la web de Twitter :-)

Code: Select all  Expand view
#include "FiveWin.ch"
#include "hbcurl.ch"

function Main()

   local hCurl

   curl_global_init()

   if ! Empty( hCurl := curl_easy_init() )
      curl_easy_setopt( hCurl, HB_CURLOPT_URL, "https://mobile.twitter.com/session/new" )
      curl_easy_setopt( hCurl, HB_CURLOPT_SSL_VERIFYPEER, .F. )
      curl_easy_setopt( hCurl, HB_CURLOPT_FAILONERROR, 1 )
      curl_easy_setopt( hCurl, HB_CURLOPT_FOLLOWLOCATION, 1 )
      curl_easy_setopt( hCurl, HB_CURLOPT_TIMEOUT, 5 )
      curl_easy_setopt( hCurl, HB_CURLOPT_COOKIEJAR, "my_cookies.txt" )
      curl_easy_setopt( hCurl, HB_CURLOPT_COOKIEFILE, "my_cookies.txt" )
      curl_easy_setopt( hCurl, HB_CURLOPT_USERAGENT, "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3 " )
       
        curl_easy_setopt( hCurl, HB_CURLOPT_DL_FILE_SETUP, "twitter.html" )
        curl_easy_perform( hCurl )
       
      curl_easy_reset( hCurl )
      MsgInfo( MemoRead( "twitter.html" ) )
   endif

   curl_global_cleanup()

return nil  
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42052
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Twitter para FWH

Postby Antonio Linares » Tue Feb 12, 2013 2:33 pm

Otro paso adelante:

Code: Select all  Expand view
#include "FiveWin.ch"
#include "hbcurl.ch"

function Main()

   local hCurl, aMatch, cPage, cAction

   curl_global_init()

   if ! Empty( hCurl := curl_easy_init() )
      curl_easy_setopt( hCurl, HB_CURLOPT_URL, "https://mobile.twitter.com/session/new" )
      curl_easy_setopt( hCurl, HB_CURLOPT_SSL_VERIFYPEER, .F. )
      curl_easy_setopt( hCurl, HB_CURLOPT_FAILONERROR, 1 )
      curl_easy_setopt( hCurl, HB_CURLOPT_FOLLOWLOCATION, 1 )
      curl_easy_setopt( hCurl, HB_CURLOPT_TIMEOUT, 5 )
      curl_easy_setopt( hCurl, HB_CURLOPT_COOKIEJAR, "my_cookies.txt" )
      curl_easy_setopt( hCurl, HB_CURLOPT_COOKIEFILE, "my_cookies.txt" )
      curl_easy_setopt( hCurl, HB_CURLOPT_USERAGENT, "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3 " )
       
      curl_easy_setopt( hCurl, HB_CURLOPT_DL_FILE_SETUP, "twitter.html" )
      curl_easy_perform( hCurl )
       
      curl_easy_reset( hCurl )
     
      cPage = MemoRead( "twitter.html" )
     
      aMatch  = HB_RegExAll( 'form action="(.*?)" method="(.*?)"', cPage, .F., .T. )
      cPage   = aMatch[ 1 ][ 2 ]
      cAction = aMatch[ 1 ][ 3 ]
     
      MsgInfo( cAction )
   endif

   curl_global_cleanup()

return nil  
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42052
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Twitter para FWH

Postby Antonio Linares » Tue Feb 12, 2013 2:56 pm

Obteniendo el token de autenticidad:

Code: Select all  Expand view
#include "FiveWin.ch"
#include "hbcurl.ch"

function Main()

   local hCurl, aMatch, cPage, cURL, cAction

   curl_global_init()

   if ! Empty( hCurl := curl_easy_init() )
      curl_easy_setopt( hCurl, HB_CURLOPT_URL, "https://mobile.twitter.com/session/new" )
      curl_easy_setopt( hCurl, HB_CURLOPT_SSL_VERIFYPEER, .F. )
      curl_easy_setopt( hCurl, HB_CURLOPT_FAILONERROR, 1 )
      curl_easy_setopt( hCurl, HB_CURLOPT_FOLLOWLOCATION, 1 )
      curl_easy_setopt( hCurl, HB_CURLOPT_TIMEOUT, 5 )
      curl_easy_setopt( hCurl, HB_CURLOPT_COOKIEJAR, "my_cookies.txt" )
      curl_easy_setopt( hCurl, HB_CURLOPT_COOKIEFILE, "my_cookies.txt" )
      curl_easy_setopt( hCurl, HB_CURLOPT_USERAGENT, "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3 " )
       
      curl_easy_setopt( hCurl, HB_CURLOPT_DL_FILE_SETUP, "twitter.html" )
      curl_easy_perform( hCurl )
       
      curl_easy_reset( hCurl )
     
      cPage = MemoRead( "twitter.html" )
     
      aMatch  = HB_RegExAll( 'form action="(.*?)" method="(.*?)"', cPage, .F., .T. )
      cURL    = aMatch[ 1 ][ 2 ]
      cAction = aMatch[ 1 ][ 3 ]
      aMatch  = HB_RegExAll( 'type="hidden" value="(.*?)"', cPage, .F., .T. )
      cAuthenticity_token = aMatch[ 1 ][ 2 ]
     
      MsgInfo( cAuthenticity_token )
   endif

   curl_global_cleanup()

return nil  
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42052
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Twitter para FWH

Postby Andrés González » Tue Feb 12, 2013 5:24 pm

:P Un 10 Antonio, lo estaba esperando, es justo el complemento que le faltan a muchas de mis aplicaciones.
Saludos

Andrés González desde Mallorca
User avatar
Andrés González
 
Posts: 628
Joined: Thu Jan 19, 2006 10:45 am
Location: Mallorca

Re: Twitter para FWH

Postby Andrés González » Tue Feb 12, 2013 5:40 pm

Alguien sabe a que se deben estos errores, los dos primeros ejemplos han funcionado bien pero los dos ultimos no me compilan. Que es lo que me falta?

Code: Select all  Expand view
--------------------Configuración: API_Twitter - Debug--------------------
Harbour 3.1.0dev (Rev. 17222)
Copyright (c) 1999-2012, http://harbour-project.org/
Borland C++ 5.82 for Win32 Copyright (c) 1993, 2005 Borland
api_twitter.c:
Turbo Incremental Link 5.69 Copyright (c) 1997-2005 Borland
Error: Unresolved external '_pcre_config' referenced from G:\FWH\1201\HARBOUR\LIB\HBRTL.LIB|hbregex
Error: Unresolved external '_pcre_stack_malloc' referenced from G:\FWH\1201\HARBOUR\LIB\HBRTL.LIB|hbregex
Error: Unresolved external '_pcre_stack_free' referenced from G:\FWH\1201\HARBOUR\LIB\HBRTL.LIB|hbregex
API_Twitter.EXE - 3 error(es), 0 advertencia(s)
 
Saludos

Andrés González desde Mallorca
User avatar
Andrés González
 
Posts: 628
Joined: Thu Jan 19, 2006 10:45 am
Location: Mallorca

Re: Twitter para FWH

Postby Andrés González » Tue Feb 12, 2013 5:52 pm

Disculpas, faltaba enlazar el $(HPATHL)\hbpcre.lib. Pero a pesar de generar el exe, cuando ejecuta la función HB_RegExAll no asigna nada en el array y la siguiente instrucción da error. A que puede ser debido?
Saludos

Andrés González desde Mallorca
User avatar
Andrés González
 
Posts: 628
Joined: Thu Jan 19, 2006 10:45 am
Location: Mallorca

Re: Twitter para FWH

Postby elvira » Tue Feb 12, 2013 6:18 pm

Antonio,

Muchas gracias por el avance.

Por cierto, ¿qué pasó con la clase para WhatsUp?.

Thanks.
elvira
 
Posts: 516
Joined: Fri Jun 29, 2012 12:49 pm

Re: Twitter para FWH

Postby Antonio Linares » Tue Feb 12, 2013 6:52 pm

Andrés,

Comprueba que valor te devuelve esta línea:

Msgnfo( curl_easy_perform( hCurl ) )

un valor distinto de cero, es error
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42052
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Twitter para FWH

Postby Andrés González » Tue Feb 12, 2013 7:45 pm

El valor que retorna es cero. No sé, parece algo de la versión de harbour o del HBPCRE.LIB. Compilo con hb31 y fw12.01.
Saludos

Andrés González desde Mallorca
User avatar
Andrés González
 
Posts: 628
Joined: Thu Jan 19, 2006 10:45 am
Location: Mallorca

Re: Twitter para FWH

Postby Antonio Linares » Tue Feb 12, 2013 9:42 pm

Andrés,

Comprueba si se crea un fichero twitter.html en donde está tu EXE y revisa su contenido, gracias :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42052
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Twitter para FWH

Postby Antonio Linares » Wed Feb 13, 2013 1:32 pm

Esta versión ya hace login en Twitter :-)

He incluido el código de UrlEncode() copiado de Tip_UrlEncode() para evitar tener que enlazar la libreria hbtip tambien.

Si abris con el navegador el fichero twitter.html que se genera al final, vereis que estais dentro de vuestra cuenta de Twitter :-)

twitter.prg
Code: Select all  Expand view
#include "FiveWin.ch"
#include "hbcurl.ch"

function Main()

   TwitterSetStatus( cUserName, cPassword )

return nil

function TwitterSetStatus( cUser, cPassword, cStatus )

   local hCurl, aMatch, cPage, cURL, cAction, cAuthenticity_token, cPost

   curl_global_init()

   if ! Empty( hCurl := curl_easy_init() )
      curl_easy_setopt( hCurl, HB_CURLOPT_URL, "https://mobile.twitter.com/session/new" )
      curl_easy_setopt( hCurl, HB_CURLOPT_SSL_VERIFYPEER, .F. )
      curl_easy_setopt( hCurl, HB_CURLOPT_FAILONERROR, 1 )
      curl_easy_setopt( hCurl, HB_CURLOPT_FOLLOWLOCATION, 1 )
      curl_easy_setopt( hCurl, HB_CURLOPT_TIMEOUT, 5 )
      curl_easy_setopt( hCurl, HB_CURLOPT_COOKIEJAR, "my_cookies.txt" )
      curl_easy_setopt( hCurl, HB_CURLOPT_COOKIEFILE, "my_cookies.txt" )
      curl_easy_setopt( hCurl, HB_CURLOPT_USERAGENT, "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3 " )
       
      curl_easy_setopt( hCurl, HB_CURLOPT_DL_FILE_SETUP, "twitter.html" )
      curl_easy_perform( hCurl )
       
      curl_easy_reset( hCurl )
     
      cPage = MemoRead( "twitter.html" )
     
      aMatch  = HB_RegExAll( 'form action="(.*?)" method="(.*?)"', cPage, .F., .T. )
      cURL    = aMatch[ 1 ][ 2 ]
      cAction = aMatch[ 1 ][ 3 ]
      aMatch  = HB_RegExAll( 'type="hidden" value="(.*?)"', cPage, .F., .T. )
      cAuthenticity_token = aMatch[ 1 ][ 2 ]
     
      cPost = "authenticity_token=" + urlencode( cAuthenticity_token ) + ;
              "&username=" + urlencode( cUser ) + ;
              "&password=" + urlencode( cPassword )
      curl_easy_init()
      curl_easy_setopt( hCurl, HB_CURLOPT_URL, cURL )
      curl_easy_setopt( hCurl, HB_CURLOPT_SSL_VERIFYPEER, .F. )
      curl_easy_setopt( hCurl, HB_CURLOPT_FAILONERROR, 1 )
      curl_easy_setopt( hCurl, HB_CURLOPT_FOLLOWLOCATION, 1 )
      curl_easy_setopt( hCurl, HB_CURLOPT_TIMEOUT, 5 )
      curl_easy_setopt( hCurl, HB_CURLOPT_COOKIEJAR, "my_cookies.txt" )
      curl_easy_setopt( hCurl, HB_CURLOPT_COOKIEFILE, "my_cookies.txt" )
      curl_easy_setopt( hCurl, HB_CURLOPT_USERAGENT, "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3 " )
      curl_easy_setopt( hCurl, HB_CURLOPT_POSTFIELDS, cPost )
      curl_easy_setopt( hCurl, HB_CURLOPT_DL_FILE_SETUP, "twitter.html" )
      curl_easy_perform( hCurl )
      curl_easy_reset( hCurl )
     
      cPage = MemoRead( "twitter.html" )
      MsgInfo( cPage )
   endif

   curl_global_cleanup()

return nil  

#pragma BEGINDUMP

#include <hbapi.h>
#include <hbapiitm.h>
#include <hbapierr.h>

HB_FUNC( URLENCODE )
{
   const char * cData     = hb_parc( 1 );
   HB_ISIZ      nLen      = hb_parclen( 1 );
   HB_BOOL      bComplete = hb_parldef( 2, HB_TRUE );
   char *       cRet;
   HB_ISIZ      nPos = 0, nPosRet = 0, nVal;
   char         cElem;

   if( ! cData )
   {
      hb_errRT_BASE( EG_ARG, 3012, NULL,
                     HB_ERR_FUNCNAME, 1, hb_paramError( 1 ) );
      return;
   }

   if( ! nLen )
   {
      hb_retc_null();
      return;
   }

   /* Giving maximum final length possible */
   cRet = ( char * ) hb_xgrab( nLen * 3 + 1 );

   while( nPos < nLen )
   {
      cElem = cData[ nPos ];

      if( cElem == ' ' )
      {
         cRet[ nPosRet ] = '+';
      }
      else if(
         ( cElem >= 'A' && cElem <= 'Z' ) ||
         ( cElem >= 'a' && cElem <= 'z' ) ||
         ( cElem >= '0' && cElem <= '9' ) ||
         cElem == '.' || cElem == ',' || cElem == '&' ||
         cElem == '/' || cElem == ';' || cElem == '_' )
      {
         cRet[ nPosRet ] = cElem;
      }
      else if( ! bComplete && ( cElem == ':' || cElem == '?' || cElem == '=' ) )
      {
         cRet[ nPosRet ] = cElem;
      }
      else /* encode! */
      {
         cRet[ nPosRet++ ] = '%';
         nVal = ( ( HB_UCHAR ) cElem ) >> 4;
         cRet[ nPosRet++ ] = nVal < 10 ? '0' + ( char ) nVal : 'A' + ( char ) nVal - 10;
         nVal = ( ( HB_UCHAR ) cElem ) & 0x0F;
         cRet[ nPosRet ] = nVal < 10 ? '0' + ( char ) nVal : 'A' + ( char ) nVal - 10;
      }

      nPosRet++;
      nPos++;
   }

   hb_retclen_buffer( cRet, nPosRet );
}

#pragma ENDDUMP
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42052
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Twitter para FWH

Postby Antonio Linares » Mon Feb 18, 2013 4:23 pm

Esta versión ya deberia funcionar. Se agradecen pruebas y comentar resultados, gracias! :-)

Code: Select all  Expand view
#include "FiveWin.ch"
#include "hbcurl.ch"

function Main()

   TwitterSetStatus( "username", "password", "Testing from an app" )

return nil

function TwitterSetStatus( cUser, cPassword, cStatus )

   local hCurl, aMatch, cPage, cURL, cAction, cAuthenticity_token, cPost

   curl_global_init()

   if ! Empty( hCurl := curl_easy_init() )
      curl_easy_setopt( hCurl, HB_CURLOPT_URL, "https://mobile.twitter.com/session/new" )
      curl_easy_setopt( hCurl, HB_CURLOPT_SSL_VERIFYPEER, .F. )
      curl_easy_setopt( hCurl, HB_CURLOPT_FAILONERROR, 1 )
      curl_easy_setopt( hCurl, HB_CURLOPT_FOLLOWLOCATION, 1 )
      curl_easy_setopt( hCurl, HB_CURLOPT_TIMEOUT, 5 )
      curl_easy_setopt( hCurl, HB_CURLOPT_COOKIEJAR, "my_cookies.txt" )
      curl_easy_setopt( hCurl, HB_CURLOPT_COOKIEFILE, "my_cookies.txt" )
      curl_easy_setopt( hCurl, HB_CURLOPT_USERAGENT, "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3 " )
       
      curl_easy_setopt( hCurl, HB_CURLOPT_DL_FILE_SETUP, "twitter.html" )
      curl_easy_perform( hCurl )
       
      curl_easy_reset( hCurl )
     
      cPage = MemoRead( "twitter.html" )
     
      aMatch  = HB_RegExAll( 'form action="(.*?)" method="(.*?)"', cPage, .F., .T. )
      cURL    = aMatch[ 1 ][ 2 ]
      cAction = aMatch[ 1 ][ 3 ]
      aMatch  = HB_RegExAll( 'type="hidden" value="(.*?)"', cPage, .F., .T. )
      cAuthenticity_token = aMatch[ 1 ][ 2 ]

      MsgInfo( cURL )
     
      cPost = "authenticity_token=" + urlencode( cAuthenticity_token ) + ;
              "&username=" + urlencode( cUser ) + ;
              "&password=" + urlencode( cPassword )
      curl_easy_init()
      curl_easy_setopt( hCurl, HB_CURLOPT_URL, cURL )
      curl_easy_setopt( hCurl, HB_CURLOPT_SSL_VERIFYPEER, .F. )
      curl_easy_setopt( hCurl, HB_CURLOPT_FAILONERROR, 1 )
      curl_easy_setopt( hCurl, HB_CURLOPT_FOLLOWLOCATION, 1 )
      curl_easy_setopt( hCurl, HB_CURLOPT_TIMEOUT, 5 )
      curl_easy_setopt( hCurl, HB_CURLOPT_COOKIEJAR, "my_cookies.txt" )
      curl_easy_setopt( hCurl, HB_CURLOPT_COOKIEFILE, "my_cookies.txt" )
      curl_easy_setopt( hCurl, HB_CURLOPT_USERAGENT, "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3 " )
      curl_easy_setopt( hCurl, HB_CURLOPT_POSTFIELDS, cPost )
      curl_easy_setopt( hCurl, HB_CURLOPT_DL_FILE_SETUP, "twitter.html" )
      curl_easy_perform( hCurl )
      curl_easy_reset( hCurl )

      cPage = MemoRead( "twitter.html" )

      aMatch  = HB_RegExAll( 'form action="(.*?)" class="(.*?)" method="(.*?)"', cPage, .F., .T. )
      cURL    = aMatch[ 1 ][ 2 ]
      cAction = aMatch[ 1 ][ 3 ]
     
      cPage = MemoRead( "twitter.html" )
      aMatch  = HB_RegExAll( 'type="hidden" value="(.*?)"', cPage, .F., .T. )
      cAuthenticity_token = aMatch[ 1 ][ 2 ]

      cPost = "authenticity_token=" + urlencode( cAuthenticity_token ) + ;
              "&display_coordinates=" + "" + ;
              "&in_reply_to_status_id=" + "" + ;
              "&lat=" + "" + ;
              "&long=" + "" + ;
              "&place_id=" + "" + ;
              "&text=" + cStatus

      curl_easy_init()
      curl_easy_setopt( hCurl, HB_CURLOPT_URL, cURL )
      curl_easy_setopt( hCurl, HB_CURLOPT_SSL_VERIFYPEER, .F. )
      curl_easy_setopt( hCurl, HB_CURLOPT_FAILONERROR, 1 )
      curl_easy_setopt( hCurl, HB_CURLOPT_FOLLOWLOCATION, 1 )
      curl_easy_setopt( hCurl, HB_CURLOPT_TIMEOUT, 5 )
      curl_easy_setopt( hCurl, HB_CURLOPT_COOKIEJAR, "my_cookies.txt" )
      curl_easy_setopt( hCurl, HB_CURLOPT_COOKIEFILE, "my_cookies.txt" )
      curl_easy_setopt( hCurl, HB_CURLOPT_USERAGENT, "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3 " )
      curl_easy_setopt( hCurl, HB_CURLOPT_POSTFIELDS, cPost )
      curl_easy_setopt( hCurl, HB_CURLOPT_DL_FILE_SETUP, "twitter.html" )
      curl_easy_perform( hCurl )
      curl_easy_reset( hCurl )

      MsgInfo( "done" )
   endif

   curl_global_cleanup()

return nil  

#pragma BEGINDUMP

#include <hbapi.h>
#include <hbapiitm.h>
#include <hbapierr.h>

HB_FUNC( URLENCODE )
{
   const char * cData     = hb_parc( 1 );
   HB_ISIZ      nLen      = hb_parclen( 1 );
   HB_BOOL      bComplete = hb_parldef( 2, HB_TRUE );
   char *       cRet;
   HB_ISIZ      nPos = 0, nPosRet = 0, nVal;
   char         cElem;

   if( ! cData )
   {
      hb_errRT_BASE( EG_ARG, 3012, NULL,
                     HB_ERR_FUNCNAME, 1, hb_paramError( 1 ) );
      return;
   }

   if( ! nLen )
   {
      hb_retc_null();
      return;
   }

   /* Giving maximum final length possible */
   cRet = ( char * ) hb_xgrab( nLen * 3 + 1 );

   while( nPos < nLen )
   {
      cElem = cData[ nPos ];

      if( cElem == ' ' )
      {
         cRet[ nPosRet ] = '+';
      }
      else if(
         ( cElem >= 'A' && cElem <= 'Z' ) ||
         ( cElem >= 'a' && cElem <= 'z' ) ||
         ( cElem >= '0' && cElem <= '9' ) ||
         cElem == '.' || cElem == ',' || cElem == '&' ||
         cElem == '/' || cElem == ';' || cElem == '_' )
      {
         cRet[ nPosRet ] = cElem;
      }
      else if( ! bComplete && ( cElem == ':' || cElem == '?' || cElem == '=' ) )
      {
         cRet[ nPosRet ] = cElem;
      }
      else /* encode! */
      {
         cRet[ nPosRet++ ] = '%';
         nVal = ( ( HB_UCHAR ) cElem ) >> 4;
         cRet[ nPosRet++ ] = nVal < 10 ? '0' + ( char ) nVal : 'A' + ( char ) nVal - 10;
         nVal = ( ( HB_UCHAR ) cElem ) & 0x0F;
         cRet[ nPosRet ] = nVal < 10 ? '0' + ( char ) nVal : 'A' + ( char ) nVal - 10;
      }

      nPosRet++;
      nPos++;
   }

   hb_retclen_buffer( cRet, nPosRet );
}

#pragma ENDDUMP
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42052
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Twitter para FWH

Postby mastintin » Tue Feb 19, 2013 11:58 am

Me funciona perfectamente .
Saludos.
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Next

Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: carlos vargas and 67 guests