2009-05-13 31 views
31

ऐसा लगता है कि कोई Google अलर्ट API नहीं है।Google अलर्ट एपीआई?

सबसे पहले, Google आपको भेजे गए ईमेल संदेश के पाठ को पार्स करने के अलावा किसी अन्य डेटाबेस में Google अलर्ट जानकारी कैसे प्राप्त करेगा?

यदि आपको पाठ का विश्लेषण करना होगा, तो आप ईमेल संदेश के प्रासंगिक टुकड़ों को पार्स करने के बारे में कैसे जानेंगे?

उत्तर

40

जब आप अलर्ट बनाते हैं, तो "डिलीवर टू" को "फीड" पर सेट करें और फिर आप फ़ीड एक्सएमएल का उपभोग कर सकते हैं क्योंकि आप किसी अन्य फ़ीड के रूप में उपयोग कर सकते हैं। डेटाबेस में पार्स और पचाने के लिए यह बहुत आसान है।

+0

एपीआई कहां है? मुझे Google अलर्ट्स एपीआई –

+0

का उपयोग करने के किसी भी दस्तावेज नहीं मिल रहे हैं यह सिर्फ एक फीड यूआरएल के रूप में एपीआई नहीं है। Https://thenextweb.com/google/2013/09/11/google-alerts-regains-rss-delivery-option-it-lost-after-google-readers-demise/ यह दिखाता है कि आपके Google अलर्ट आरएसएस को कैसे प्रबंधित करें फ़ीड करें और यूआरएल प्राप्त करें। –

2

मैं जानता हूँ कि इस पोस्ट थोड़ा पुराना है, लेकिन एक बहुत खोजने के बाद, मैं अंत में एक काम करने के लिए php पुस्तकालय पाया प्रोग्राम के रूप में पढ़ने, हटाने और गूगल सचेतक बनाने के लिए:

http://coders11.com/googlealertsapi

+6

वह एपीआई अब स्वतंत्र रूप से उपलब्ध नहीं है। FWIW। –

+0

लेकिन यह अभी भी काम कर रहा है, फिर भी – MazarD

12
class googleAlerts{ 
    public function createAlert($alert){ 
     $USERNAME = '[email protected]'; 
     $PASSWORD = 'YYYYYY'; 
     $COOKIEFILE = 'cookies.txt'; 

     $ch = curl_init(); 
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); 
     curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
     curl_setopt($ch, CURLOPT_COOKIEJAR, $COOKIEFILE); 
     curl_setopt($ch, CURLOPT_COOKIEFILE, $COOKIEFILE); 
     curl_setopt($ch, CURLOPT_HEADER, 0); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120); 
     curl_setopt($ch, CURLOPT_TIMEOUT, 120); 

     curl_setopt($ch, CURLOPT_URL, 
      'https://accounts.google.com/ServiceLogin?hl=en&service=alerts&continue=http://www.google.com/alerts/manage'); 
     $data = curl_exec($ch); 

     $formFields = $this->getFormFields($data); 

     $formFields['Email'] = $USERNAME; 
     $formFields['Passwd'] = $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, '<title>') === false) { 
      return false; 

     } else { 
      curl_setopt($ch, CURLOPT_URL, 'http://www.google.com/alerts'); 
      curl_setopt($ch, CURLOPT_POST, 0); 
      curl_setopt($ch, CURLOPT_POSTFIELDS, null); 

      $result = curl_exec($ch); 

      curl_setopt($ch, CURLOPT_URL, 'http://www.google.com/alerts/create'); 
      curl_setopt($ch, CURLOPT_POST, 0); 
      $result = curl_exec($ch); 
      //var_dump($result); 
      $result = $this->getFormFieldsCreate($result); 
      $result['q'] = $alert; 
      $result['t'] = '7'; 
      $result['f'] = '1'; 
      $result['l'] = '0'; 
      $result['e'] = 'feed'; 
      unset($result['PersistentCookie']); 

      $post_string = ''; 
      foreach($result as $key => $value) { 
       $post_string .= $key . '=' . urlencode($value) . '&'; 
      } 

      $post_string = substr($post_string, 0, -1); 
      curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string); 
      $result = curl_exec($ch); 
      curl_setopt($ch, CURLOPT_URL, 'http://www.google.com/alerts/manage'); 
      $result = curl_exec($ch); 
      if (preg_match_all('%'.$alert.'(?=</a>).*?<a href=[\'"]http://www.google.com/alerts/feeds/([^\'"]+)%i', $result, $matches)) { 
       return ('http://www.google.com/alerts/feeds/'.$matches[1][0]); 
      } else { 
       return false; 
      } 


     } 
    } 

    private function getFormFields($data) 
    { 
     if (preg_match('/(<form.*?id=.?gaia_loginform.*?<\/form>)/is', $data, $matches)) { 
      $inputs = $this->getInputs($matches[1]); 

      return $inputs; 
     } else { 
      die('didnt find login form'); 
     } 
    } 
    private function getFormFieldsCreate($data) 
    { 
     if (preg_match('/(<form.*?name=.?.*?<\/form>)/is', $data, $matches)) { 
      $inputs = $this->getInputs($matches[1]); 

      return $inputs; 
     } else { 
      die('didnt find login form1'); 
     } 
    } 


    private function getInputs($form) 
    { 
     $inputs = array(); 

     $elements = preg_match_all('/(<input[^>]+>)/is', $form, $matches); 

     if ($elements > 0) { 
      for($i = 0; $i < $elements; $i++) { 
       $el = preg_replace('/\s{2,}/', ' ', $matches[1][$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; 
    } 
} 
$alert = new googleAlerts; 
echo $alert->createAlert('YOUR ALERT'); 

यह होगा के आरएसएस फ़ीड करने के लिए वापस लिंक आपकी सूचना के नव निर्मित

+0

मैंने कोड का परीक्षण नहीं किया है - लेकिन जैसे आपने अलर्ट बनाने के लिए कोड साझा किया है, क्या अलर्ट को हटाने या संपादित करने के लिए कुछ कोड भी है? –

+4

भविष्य के पाठकों के लिए, इस दिन के रूप में यह समाधान अब काम नहीं करता है। –

+0

किसी को भी इस कोड में अपडेट मिला है? – MarcoZen

1

तुम भी बाहर इस C# library

+1

लिंक मर चुका है। Google कैश्ड संस्करण: http://webcache.googleusercontent.com/search?q=cache:cYyxb6oQ3oYJ:www.frickingnutz.com/%3Fq%3Dnode/51+&cd=6&hl=hi&ct=clnk&gl=ie – Seany84

0

अजगर में की कोशिश कर सकते Google अलर्ट लाइब्रेरी galerts है। आप शायद गीथब कोड में देख सकते हैं: https://github.com/jab/galerts

संबंधित मुद्दे