Jump to content

login to twitter or google

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
11 replies to this topic

#1
joe2010

joe2010

    Newbie

  • Members
  • PipPip
  • 10 posts
I have done 2 projects where i needed to login to twitter and google but was not able to using curl or snoopy (from snoopy.sourceforge.net)

i was able to login using Java HTTP client. but that is a head ache to install as most hosts do not support Java and on client systems they are relucatant to put java then put my jars etc.

so my question is - are there any better http clients in Java that work for these sites? I guess its got to do with the cookie/ session handling as everything else is the same in both codes (get the initial login page, submit a form via post, follow the redirects and see if your logged in or get an error message)

has anyone succesfully logged in to google using php and then queries a page via post ...?

if so can you share the snoopy like client code and usage?

#2
Feral

Feral

    Programmer

  • Members
  • PipPipPipPip
  • 162 posts
What exactly are you trying to do? Why not just use the google/twitter api to access the information that you need on google or twitter?

#3
joe2010

joe2010

    Newbie

  • Members
  • PipPip
  • 10 posts
the client does not want to use the api at twitter. need to do keyword people search.

google - there is no api for the google ads keyword searcher.

anyway right now just want to be able to login. so looking for a more robust php client than snoopy, curl. something like Java http client that is able to login

CODE in attached text


this is the java code and it uses HttpClient

in php I can parse the authenticity_token from the login screen but when i submit the post form it does not login, instead twitter redirects me to the default non logged in home page.

FYI this code needs these jars
G:\j\j\o1\httpClient\h3\commons-logging-1.1.1.jar;G:\j\j\o1\httpClient\h3\commons-codec-1.3.jar;G:\j\j\o1\httpClient\h3\commons-httpclient-3.1.jar

Attached Files

  • Attached File  samp.txt   11.46K   146 downloads


#4
Feral

Feral

    Programmer

  • Members
  • PipPipPipPip
  • 162 posts
Well I haven't personally had do try anything like that myself (yet), but I did find this code

<?php
/* "AdSense totals sent via SMS to cellphone" 

http://www.webmasterworld.com/forum89/5349.htm

 
"Follow your Adsense earnings with an RSS reader" 

http://curl.askapache.com/libcurl/php/examples/rss-adsense.html

 
"Auto-Login to Google Analytics to impress Clients"
http://www.askapache.com/webmaster/login-google-analytics.html */
 
// Uncomment to only allow from IP 1.1.1.1
// if($_SERVER['REMOTE_ADDR'] !== '1.1.1.1') die();
$username=urlencode('myemail@gmail.com');
$password="mypassword";
$gacookie="./.gacookie";
 
$postdata="Email=$username&Passwd=$password&GA3T=5AS_gBsvDHI&nui=15&fpui=3&askapache=http://www.askapache.com/"
."&service=adsense&ifr=true&rm=hide&itmpl=true&hl=en_US&alwf=true&continue=https://www.google.com/adsense/report/overview&null=Sign in";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL,"https://www.google.com/accounts/ServiceLoginBoxAuth");
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $gacookie);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $gacookie);
curl_setopt ($ch, CURLOPT_REFERER, 'https://www.google.com/adsense/report/overview');
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
$AskApache_result = curl_exec ($ch);
curl_close($ch);
echo $AskApache_result;
unlink($gacookie);
exit;
?>

form here to loog into ansense using cUrl maybe you will find it usefull.

#5
Feral

Feral

    Programmer

  • Members
  • PipPipPipPip
  • 162 posts
sorry double post

Edited by Feral, 21 January 2010 - 03:55 AM.


#6
joe2010

joe2010

    Newbie

  • Members
  • PipPip
  • 10 posts
nice i will have to experiment with other google page logins as i dont have a adsense account so it just sends me the loginto adsense page ... which happens even on the browser.
looking at the vars on the google account page

#7
joe2010

joe2010

    Newbie

  • Members
  • PipPip
  • 10 posts
i was not able to get it to work
i ran it via the command line on windows, can see the .gacookie file but still get response :

cookies are turned off. i edited the script to parse GALX and dsh values from the google home page sign in form and then submit it

attached d.zip need to makea file auth.php in same folder which has your credentials:
<?php


$username='emal';

$password=urlencode("pass");

Attached Files

  • Attached File  d.zip   1.22K   48 downloads


#8
Feral

Feral

    Programmer

  • Members
  • PipPipPipPip
  • 162 posts
have you tried running it in a browser instead of the command line? it simply might be that the command line does not have a way to handle the cookies and sends no response when the server tries to create one.

Or is it a requirement that the application be run from the command line?

#9
joe2010

joe2010

    Newbie

  • Members
  • PipPip
  • 10 posts
its the opposite: from the command line the .gacookies file is made and you can open it and see the cookes

when i run from the browser it does not make the file. not sure why it does not, i can save the resultant html so why cant curl make the file.
maybe i need the correct option to tell curl to continue using the cookie file - after the first request to load and submit cookies from there.

#10
joe2010

joe2010

    Newbie

  • Members
  • PipPip
  • 10 posts
i get the cookie file from the browser too but same result

i tried to keep the same $ch object
only change the options that need chanding - in hope htat it will send the cookies again but still google says your cookies are turned off

curl_setopt ($ch, CURLOPT_URL,"google link removed");//see attached
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt ($ch, CURLOPT_COOKIEJAR, $gacookie);//dont refresh the cookie jar?
//curl_setopt ($ch, CURLOPT_COOKIEFILE, $gacookie);

curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt( $ch, CURLOPT_MAXREDIRS, 40 );
curl_setopt ($ch, CURLOPT_POST, 1);


#11
Feral

Feral

    Programmer

  • Members
  • PipPipPipPip
  • 162 posts
Hmm sounds like a challenge, I'll have to see if I can find some time this weekend to see if I have any better results.

#12
joe2010

joe2010

    Newbie

  • Members
  • PipPip
  • 10 posts
it will be useful for a number of utilities, even for our internal site that is posted to by another team via a CMS tool