/ Published in: PHP
Use this API to access names and addresses in a user's webmail (Gmail, AOL, Hotmail, and Yahoo). Make it easy to send friend invites for a social site and import contact lists. Rapleaf maintains up to date code on the importer and never stores passwords.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php /* * Helper class for the Rapleaf Address Book API * (http://www.rapleaf.com/apidoc/v2/abook) * Gets the XML response from the Rapleaf server and parses it into a PHP object. * * Usage: * 1. $abook = new RapleafAbook(api_key[,url]) to initialize * 2. $result = $abook->getData(email, password) to query the API for a contact list * See the function definitions for details. * * 03/01/2008 * */ class RapleafAbook { var $url; var $api_key; var $status; function RapleafAbook($api_key, $url = 'http://api.rapleaf.com/v2/abook') { $this->api_key = $api_key; $this->url = $url; $this->status = ''; } function getData($email, $pass) { # assemble post_data string $post_data = "login=$email&password=$pass"; $response = $this->sendPostRequest($this->url, $post_data); # the return structure 'status' => '', # HTTP status code returned by the server 'error' => '', # error message if there are any ); $result['status'] = $this->status; if ($this->status == '200') { #OK $result['contacts'] = $this->xmlToObj($response); } elseif ($this->status == '400') { $result['error'] = 'The request did not contain all required parameters: '.$response; } elseif ($this->status == '401') { $result['error'] = 'API key was not provided or is invalid.'; } elseif ($this->status == '420') { $result['error'] = 'Login failed.'; } elseif ($this->status == '500') { $result['error'] = 'There was an unexpected error on our server. This should be very rare and if you see it please contact [email protected].'; } elseif ($this->status == '520') { $result['error'] = 'There was an error while reading the contacts from the address book.'; } return $result; } # Parse the xml response text into an associative array function xmlToObj($str) { foreach ($xml->contact as $contact) { } return $result; } # Returns the xml response on success, sets the error message on failure function sendPostRequest($url, $post_data) { ); return $data; } } ?>
URL: http://www.rapleaf.com/developer