Section 16.3. Getting User Information


16.3. Getting User Information

It's fairly easy to construct an example in PHP that uses the KeywordEstimatorService to allow a user to enter a keyword and a maximum bid for that keyword, and get traffic estimates for ads targeted to that keyword.

16.3.1. Obtaining Authentication Headers

The first step is to get the user to input the information required for authentication:

  • Email address associated with an AdWords account

  • Password for the account

  • UserAgent (an arbitrary string)

  • AdWords Developer key

An interface like that shown in Figure 16-2 can be used to get this information.

Figure 16-2. For this application, the user enters authentication information, but when keyword automation is used as part of an automated ad placement program this information would be provided by the system


Example 16-1 shows the HTML for the form that lets the user enter information about a keyword to be estimated. The form posts the user input to estimate_keyword.php, which does the actual estimation.

Example 16-1. Obtaining authentication information from the user (account.php)

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Enter Account Info</title> </head> <body> <h1>Enter Account Information</h1> <form action="estimate_keyword.php" method="POST"> <table cellspacing=15> <tr><td> Enter your AdWords email: </td><td> <input type="text" name="email" value=""> </td></tr><tr><td> Enter your AdWords password: </td><td> <input type="password" name="password" value=" "> </td></tr><tr><td> Enter User Agent (anything you like): </td><td> <input type="text" name="useragent" value="Keyword Estimatation Demo"> </td></tr><tr><td> Enter your developer token: </td><td> <input type="text" name="token" value=" "> </td></tr> <tr><td></td><td> <input type="submit" name"Continue" value="Next"> </td></tr> </table> </form> </body> </html>

16.3.2. Getting a Keyword and Maximum CPC

The next form, shown in Figure 16-3, is used to get a keyword and maximum CPC for the keyword.

A keyword can be a multiple-word phrase. In fact, the best keywords usually consist of several words, because longer phrases generally produce more pinpointed results.


Figure 16-3. The user enters the keyword (or phrase) for estimation along with a maximum CPC


The code in Example 16-2 shows gathering the authentication information that was previously posted, adding XML and combining it to make a header, and saving the header using PHP's session-tracking facility (see Chapter 14 for a detailed explanation of this process). Next, in Example 16-2, a form that allows the user to enter the keyword and bid is displayed, and the form is posted to show_estimate.php.

Example 16-2. Getting a keyword and maximum CPC (estimate_keyword.php)

 <?php session_start(  ) ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Enter Keyword for Estimation</title> </head> <body> <?php require_once('NuSOAP/nusoap.php'); require_once('hd_lib.inc'); echo "<h1>Enter a Keyword for Estimation</h1>"; $email = $_POST['email']; $password = $_POST['password']; $useragent = $_POST['useragent']; $token = $_POST['token'];   // Set up the authentication headers $email = makeDocLit ("email", $email); $password = makeDocLit ("password", $password); $useragent = makeDocLit ("useragent", $useragent); $token = makeDocLit ("token", $token); $header = $email . $password . $useragent . $token; session_register('header');   echo '<form action="show_estimate.php" method="POST"> <table cellspacing=15> <tr><td> Enter the keyword to estimate: </td><td> <input type="text" name="keyword" value="digital photo"> </td></tr><tr><td> Enter the maximum CPC you are willing to pay in micro-units: </td><td> <input type="text" name="maxCpc" value="500000"> </td></tr><tr><td></td><td> <input type="submit" name"Continue" value="Estimate"> </td></tr> </table> </form>'; ?> </body> </html>



Google Advertising Tools. Cashing in with AdSense, AdWords, and the Google APIs
Google Advertising Tools: Cashing in with Adsense, Adwords, and the Google APIs
ISBN: 0596101082
EAN: 2147483647
Year: 2004
Pages: 145
Authors: Harold Davis

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net