diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8675c2d --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +config.php +queries.txt +cookies.txt \ No newline at end of file diff --git a/README.md b/README.md index 9c53303..6e5c5ac 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,19 @@ google_alerts_creator ===================== -A class for creating Google Alerts in bulk ( even though there is not an official API ). + +Notes +----- +- A class for creating Google Alerts in bulk ( even though there is not an official API ). +- Based on this Stack Overflow question and answer + - http://stackoverflow.com/questions/13528747/how-to-create-new-google-alert-delivering-it-to-feed-using-php-curl + + +Usage +----- +1. copy `config.php.example` to `config.php` + - add your google account credentials + - set your desired alert settings +2. copy `queries.txt.example` to `queries.txt` + - add your alert queries to this file, one per line +3. execute `create_google_alerts.php` \ No newline at end of file diff --git a/config.php.example b/config.php.example new file mode 100644 index 0000000..1de3e97 --- /dev/null +++ b/config.php.example @@ -0,0 +1,41 @@ + \ No newline at end of file diff --git a/create_google_alerts.php b/create_google_alerts.php new file mode 100644 index 0000000..76d2064 --- /dev/null +++ b/create_google_alerts.php @@ -0,0 +1,17 @@ +createAlert( $query ); + } + + echo "\n\n"; + +?> \ No newline at end of file diff --git a/google_alerts_class.php b/google_alerts_class.php new file mode 100644 index 0000000..5080794 --- /dev/null +++ b/google_alerts_class.php @@ -0,0 +1,132 @@ +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'); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string); + + $result = curl_exec($ch); + + if (strpos($result, '