Jump to content

API Connectivity


Tsalagi

Recommended Posts

Howdy. I"m trying to work with an API from Project Votes Smart but they have very little in the way of support and documentation. In the code example they provide there is a value already provided in the array located above the html code, which returns the information from the class it uses. There are two things that I'm stuck on.  I would like to know how to populate a drop down list from their array and how to pass data from a search form to the array so I can display information provided by the class. For instance instead of the "stateId" provided in the example, I would like the user to enter a zip code and pass that to the array. They have a location class that uses a zip code array.

Hope this isn't too confusing.

Thanks for the help.

<?php

require_once("VoteSmart.php");

// Initialize the VoteSmart object
$obj = new VoteSmart(

        'CandidateBio.getBio', 

        Array(
                'candidateId' => 9026
        ));

// Get the SimpleXML object
$x = $obj->getXmlObj();

echo '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- pwned -->
<html lang="en">
<body>';

// Check and make sure there is no error

if (isset($x->errorMessage)) { // If there is, let's handle it
        
        echo '
        <div>' . $x->errorMessage . '</div>';
        
} else { // If not, let's go ->
        
        // some quick and dirty assembly
        $candName = $x->candidate->firstName . ' ' . $x->candidate->middleName . ' ' . $x->candidate->lastName . ' ' . $x->candidate->suffix;
        if (!empty($x->candidate->photo)) $photo = '<img src="' . $x->candidate->photo . '" />';
        
        echo '
        <div>
                <a href="' . $x->generalInfo->linkBack . '">' . $x->generalInfo->title . '</a>
        </div>
        <br /><br />
        <table>
                <tr>
                        <td>Name</td><td>' . $candName . '</td>
                </tr><tr>
                        <td>Birth</td><td>' . $x->candidate->birthDate . ' (' . $x->candidate->birthPlace . ')</td>
                </tr><tr>
                        <td>Gender</td><td>' . $x->candidate->gender . '</td>
                </tr><tr>
                        <td>Photo</td><td>' . $photo . '</td>
                </tr><tr>
                        <td>Party</td><td>' . $x->office->parties . '</td>
                </tr><tr>
                        <td>Office</td><td>' . $x->office->name . '</td>
                </tr>
			<tr><td>District</td><td>' . $x->branch->name . '</td>
			</tr>
			<tr><td>State</td><td>' . $x->office->title . '</td>
			</tr>
                ';
        
}

echo '
</body>
</html>';

?>

Link to comment
Share on other sites

Howdy. I"m trying to work with an API from Project Votes Smart but they have very little in the way of support and documentation. In the code example they provide there is a value already provided in the array located above the html code, which returns the information from the class it uses. There are two things that I'm stuck on.  I would like to know how to populate a drop down list from their array and how to pass data from a search form to the array so I can display information provided by the class. For instance instead of the "stateId" provided in the example, I would like the user to enter a zip code and pass that to the array. They have a location class that uses a zip code array.

Hope this isn't too confusing.

Thanks for the help.

<?php

require_once("VoteSmart.php");

// Initialize the VoteSmart object
$obj = new VoteSmart(

        'CandidateBio.getBio', 

        Array(
                'candidateId' => 9026
        ));

// Get the SimpleXML object
$x = $obj->getXmlObj();

echo '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- pwned -->
<html lang="en">
<body>';

// Check and make sure there is no error

if (isset($x->errorMessage)) { // If there is, let's handle it
        
        echo '
        <div>' . $x->errorMessage . '</div>';
        
} else { // If not, let's go ->
        
        // some quick and dirty assembly
        $candName = $x->candidate->firstName . ' ' . $x->candidate->middleName . ' ' . $x->candidate->lastName . ' ' . $x->candidate->suffix;
        if (!empty($x->candidate->photo)) $photo = '<img src="' . $x->candidate->photo . '" />';
        
        echo '
        <div>
                <a href="' . $x->generalInfo->linkBack . '">' . $x->generalInfo->title . '</a>
        </div>
        <br /><br />
        <table>
                <tr>
                        <td>Name</td><td>' . $candName . '</td>
                </tr><tr>
                        <td>Birth</td><td>' . $x->candidate->birthDate . ' (' . $x->candidate->birthPlace . ')</td>
                </tr><tr>
                        <td>Gender</td><td>' . $x->candidate->gender . '</td>
                </tr><tr>
                        <td>Photo</td><td>' . $photo . '</td>
                </tr><tr>
                        <td>Party</td><td>' . $x->office->parties . '</td>
                </tr><tr>
                        <td>Office</td><td>' . $x->office->name . '</td>
                </tr>
			<tr><td>District</td><td>' . $x->branch->name . '</td>
			</tr>
			<tr><td>State</td><td>' . $x->office->title . '</td>
			</tr>
                ';
        
}

echo '
</body>
</html>';

?>

 

This issue has been solved by passing values to avariable with a form

thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.