Hola, tengo el siguiente codigo que sirve para crear alertas de google, busque un API anteriormente pero ya no existe, el problema es que al ejecutar el codigo me sale una pantalla que dice esto...
Verifica que eres tú
Parece que algo cambió en tu modo de acceder a la cuenta. Completa el siguiente paso para garantizarnos que eres tú y no otra persona que se está haciendo pasar por ti. Más información. Y aparecen las opciones de Selecciona un método de verificación:
El codigo es el siguiente...
Código PHP:
Ver original<?php
class Google_alerts_class
{
public function createAlert( $search ) {
require('config.php' );
curl_setopt($ch, CURLOPT_USERAGENT
, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"); curl_setopt($ch, CURLOPT_COOKIEJAR
, GOOGLE_COOKIEFILE
); curl_setopt($ch, CURLOPT_COOKIEFILE
, GOOGLE_COOKIEFILE
);
'https://accounts.google.com/ServiceLogin?hl=es-419&continue=https://www.google.com.mx/%3Fgws_rd%3Dssl');
$formFields = $this->getFormFields( $data );
$formFields['Email'] = GOOGLE_USERNAME;
$formFields['Passwd'] = GOOGLE_PASSWORD;
unset($formFields['PersistentCookie']);
$post_string = '';
foreach($formFields as $key => $value) {
$post_string .= $key . '=' . urlencode($value) . '&'; }
$post_string = substr($post_string, 0, -1);
curl_setopt($ch, CURLOPT_URL
, 'https://accounts.google.com/ServiceLoginAuth');
if (strpos($result, '<title>Redirecting') === false) { } else {
curl_setopt($ch, CURLOPT_URL
, 'https://www.google.com/alerts');
// Create alert
preg_match('/<input type="hidden" name="x" value="([^"]+)"/', $result, $matches);
"x" => $matches[1], // anti-XSRF key
"q" => $search, // Search term
"t" => ALERT_RESULT_TYPE, // Result type: 7-everything, 8-discussions
"f" => ALERT_FREQUENCY, // Frequency: 0: as it happens, 1: daily, 6: weekly
"l" => ALERT_QUALITY, // All results: 1, best results: 0
"e" => GOOGLE_USERNAME // Type of delivery: rss: "feed"
);
$post_string = '';
foreach($post as $key => $value) {
$post_string .= $key . '=' . urlencode($value) . '&'; }
$post_string = substr($post_string, 0, -1);
curl_setopt($ch, CURLOPT_URL
, 'https://www.google.com/alerts/create');
preg_match('#<a href="(https://www.google.com/alerts/feeds/[\d/]+)"#', $result, $matches);
$top_alert = $matches[1];
return $top_alert;
}
}
private function getFormFields($data)
{
if (preg_match('/(<form.*?id=.?gaia_loginform.*?<\/form>)/is', $data, $matches)) { $inputs = $this->getInputs($matches[1]);
return $inputs;
} else {
die("didn't find login form"); }
}
private function getInputs($form)
{
if ($elements > 0) {
for($i = 0; $i < $elements; $i++) {
if (preg_match('/name=(?:["\'])?([^"\'\s]*)/i', $el, $name)) { $name = $name[1];
$value = '';
if (preg_match('/value=(?:["\'])?([^"\'\s]*)/i', $el, $value)) { $value = $value[1];
}
$inputs[$name] = $value;
}
}
}
return $inputs;
}
} // end class
?>
congif.php
Código PHP:
Ver original<?php
// --- GOOGLE ACCOUNT SETTINGS -------------------------
define( 'GOOGLE_PASSWORD', 'theangels'); // --- ALERT SETTINGS ----------------------------------
// alert frequency ( how often you recieve emails )
// - as it happens: 0
// - daily: 1
// - weekly: 6
define( 'ALERT_FREQUENCY', 1 ); // result type ( what to seaerch )
// - everything: 7
// - discussions: 8
// - news: 1
// - blogs: 4
// - video: 9
// - books: 22
define( 'ALERT_RESULT_TYPE', 7 ); // result quality filter
// - best results: 0
// - all results: 1
// --- CURL SETTINGS ----------------------------------
define( 'GOOGLE_COOKIEFILE', 'cookies.txt' ); ?>
create_google_alerts.php
Código PHP:
Ver original<?php
require('google_alerts_class.php' );
$Ga = new Google_alerts_class();
$queries = explode( "\n", $query_file_contents );
foreach( $queries as $query ) {
echo "\n - '$query' Alert Created";
$Ga->createAlert( $query );
}
echo "\n\n";
?>