All i need - it is create google alert connected to my account, which should be delivered to my feed. For auth i'm using curl
function googleAuthenticate($username, $password, $source, $service = 'alerts') {
$session_token = $source . '_' . $service . '_auth_token';
if (isset($_SESSION[$session_token])) {
echo 'уже есть';
return $_SESSION[$session_token];
}
// get an authorization token
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.google.com/accounts/ClientLogin");
$post_fields = "accountType=" . urlencode('HOSTED_OR_GOOGLE')
. "&Email=" . urlencode($username)
. "&Passwd=" . urlencode($password)
. "&source=" . urlencode($source)
. "&service=" . urlencode($service);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_HEADER, true);
$response = curl_exec($ch);
curl_close($ch);
if (strpos($response, '200 OK') === false) {
return false;
}
// find the auth code
preg_match("/(Auth=)([\w|-]+)/", $response, $matches);
if (!$matches[2]) {
return false;
}
$_SESSION[$session_token] = $matches[2];
return $matches[2];}
but i couldn't fill form on google.com/alerts
You can use this lib: http://coders11.com/googlealertsapi/
It recently became commercial, but it works very well:
Based on code from this page:
Login to Google with PHP and Curl, Cookie turned off?