Rapleaf通讯簿API
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Rapleaf通讯簿API相关的知识,希望对你有一定的参考价值。
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.
<?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; } } ?>
以上是关于Rapleaf通讯簿API的主要内容,如果未能解决你的问题,请参考以下文章