GIDForums  

Go Back   GIDForums > Web Promotion Forums > Search Engine Optimization Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 03-Sep-2003, 17:11
jrobbio's Avatar
jrobbio jrobbio is offline
Regular Member
 
Join Date: Jan 2003
Location: Loughborough, England
Posts: 840
jrobbio will become famous soon enough

Check your keyword position using Google API


I received this via the JimWorld newsletter that I'd apparently signed up to, but since it is under the GPL I thought I'd post it here:
Quote:
Pull up a seat, boys and girls... this one's worth the price of admission.

We're going to work this week on a cool tool that uses the GoogleAPI. My intent
here is to show you just how easy it is to use, and how you can do something
cool, if you just think outside the box a bit. This code sample was done in
PHP, but can be easily replicated in Perl, or any other language that has simple
opject access protocol (SOAP) support. The relevant libraries that you need
are listed at the end of this article. Note that in most cases, your ISP's
installation of Perl or PHP will not include the SOAP extensions by default, so
you'll have to ask that they be installed for you. If you run your own machine,
you should be able to install the necessary core libraries by yourself in just a
few minutes. The "SOAP_Google" class listed below, which is the basis for this
article, is free for your use by visiting the author's Web site. You can
install it into the same directory as your GoogleAPI scripts. Ok, here we
go...


One of the things essential to any SEO, and really, to anyone who operates a Web
site, is to know where they rank at Google for a given search term or phrase.
Using the GoogleAPI, we can very easily find out where a site ranks, without
having to visit Google.com and going dizzy reading the results. The source code
for "test.php" follows, and is commented so that you can follow the logic.
Happy position checking!
PHP Code:

<?php
    // test.php
    // A simple way to check positions for a given domain, for given
    //keywords at Google.com.  Uses the googleAPI to make things easier
    // This application is free for non-commercial use under the GPL
    // Please keep this copyright and header intact.
    // (c) 2003 John Cokos, JimWorld.com
    

    // This pulls in the SOAP_Google Class file 
   //require_once 'google.php';
 
    // For Clarity, let's use real variable names //
    $terms = $_POST[keyword];
    $domain = $_POST[domain];

    // Draw a very simple form //
    echo "
       <table> 
       <tr><td>
        <form action='test.php' method='post'>
          Keyword / Phrase: <input name='keyword' size='50' value='$terms' />
          <br />
          Domain to Check: <input name='domain' size='50' value='$domain' />
          <br />         
          <center><input type='submit' /></center>
        </form>
       </td></tr>
       </table>
       <hr />
    ";

    // If the form has been filled out .... get to work.
    if ( $terms && $domain ) { 

        // Create a new oject using the SOAP_Google Class.  All you need to
        // Do is give it your googleAPI license key

        $google = new SOAP_Google('YOUR-GOOGLE-LICENSE-KEY');

        // Use that Google object to run a search.  In this example, we simply
        // pass along the search terms, and ask for the first 10 results.  You 
        // can also specify a higher number of results, where to start from, 
        // turn on safe searching, etc.  For our purposes, we just want the
        // basic top 10 results.
        $result = $google->search(
          array(
            'query' => $term,
            'maxResults' => 10
          )
        );

        // Now, the results of searching Google are in an object called
"$result"
        // This is actually an array of objects, that we can iterate through
        // to do what we want
 
        // Make sure that we actually got results //
        if (false !== $result) {

            // Tell the user what we have done //
            echo "Checked: <b>$domain</b> for <b>$term</b> .... <br /><br />";
            // What we're going to be doing is reporting the position of our
           //domain

            // For the given search term, so first, we make sure that we're
            //starting
            // at "0", so that the counter works right.
            $position = 0;

            // Now, Iterate through the result set.  Each "$listing" is a PHP
            //Object
            // that contains the data for the current search result in the list
            foreach ( $result->resultElements as $listing ) { 

                // Increase the position Counter
                $position++;

               // If the domain we asked to check ($domain) is contained     
               //within the URL of the current search result, we have a match, 
               //so let's display it on screen just like a Google result.  Note 
               //that for the purposes of what we're doing, we really don't 
               //need to display the listing, just report the position, but I 
               //wanted you to see how to manipulate the results.

                // Note that this will show you every match of the domain that
                //it finds so that you can see if you appear multiple times.

                if ( eregi( $domain, $url ) ) { 

                    // Create some logical variable names //
                    $title = $listing->title;
                    $snippet = $listing->snippet;
                    $description = $listing->summary;
                    $url = $listing->URL;
 
                    // Dump it out just like a listing //
                    echo "
                       <div style='font-family:verdana,arial; font-size:.8em'>
                       <blockquote>
                       <b>Position: $position</b><br /><br />
                       <a href='$url'>$title</a><br />
                       $snippet</br />
                       <span style='color:#708090'>Description:</span>
                       $description<br />
                       <span style='color:green'><i>$url</i></span>
                       </div>
                       </blockquote>
                       <hr />
                    ";
                    $found = 1;                    
                }
            }

            // If we did not appear in the top 10, report it.
            if ( ! $found ) { echo "Not found in first 10 positions"; }
        } 

        // This will return a simple error message if we got nothing back
        //from Google
        else {
          echo 'Query failed.';
        }
    }

    // This will show if the form was not filled out //
    else { echo "Please fill in the form above completely"; }

?>


Resources:

Google API Sign up: http://www.google.com/apis/
PHP PEAR::SOAP Extension: http://pear.php.net/package-info.php?pacid=87
SOAP_Google Class for PHP: http://www.sebastian-bergmann.de/?page=google
Perl SOAP Library: http://search.cpan.org/author/KULCHENKO/SOAP-Lite-0.55/

Rob
  #2  
Old 03-Sep-2003, 17:27
BobbyDouglas's Avatar
BobbyDouglas BobbyDouglas is offline
Regular Member
 
Join Date: Aug 2003
Posts: 789
BobbyDouglas has a spectacular aura aboutBobbyDouglas has a spectacular aura about
AWESOME script. I will be adding that on my site.
  #3  
Old 21-Jun-2004, 10:05
Vincenzo Vincenzo is offline
New Member
 
Join Date: Jun 2004
Posts: 2
Vincenzo is on a distinguished road
Hi!

I try to used the script, and I need to do this changes for run it:

Line 11 : //require_once 'google.php';
Line 11 : require_once 'google.php';

Line 54 : "$result"
Line 54: "$result";

But, anyway, the scripts always return me "Query Failed"

Any idea ?

Thanks!! And excuse my poor english

Gracias!!!
  #4  
Old 22-Jun-2004, 07:40
Vincenzo Vincenzo is offline
New Member
 
Join Date: Jun 2004
Posts: 2
Vincenzo is on a distinguished road
Any idea for fix the script?
  #5  
Old 23-Jul-2004, 07:32
jrobbio's Avatar
jrobbio jrobbio is offline
Regular Member
 
Join Date: Jan 2003
Location: Loughborough, England
Posts: 840
jrobbio will become famous soon enough
I could never get it to work either? Did anyone succeed?

Rob
  #6  
Old 20-Jul-2006, 15:29
noahbritton noahbritton is offline
New Member
 
Join Date: Jul 2006
Posts: 1
noahbritton is on a distinguished road

Re: Check your keyword position using Google API


Anyone figure this out. It would be very useful for me to have this script. Anyone?
 
 

Recent GIDBlogMeeting the populace by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Google Ads on Opera: Is it right? JdS Computer Software Forum - Linux 4 06-Dec-2003 17:10
Mozilla Google Toolbar - Googlebar jrobbio Computer Software Forum - Linux 0 07-Jun-2003 04:40
Search Engine Positioning 101 and 201 "How To" Tips... 000 Search Engine Optimization Forum 0 29-May-2003 10:34
Have an email sent to you when Google crawls your PHP site jrobbio MySQL / PHP Forum 5 26-Feb-2003 22:38
Google indexes Zeal/LookSmart listings!? JdS Search Engine Optimization Forum 1 12-Oct-2002 12:37

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 06:00.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.