#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