|
hi5.php: <?php class Connection { private $sServer = 'http://api.hi5.com/'; private $aKey; private $aUsername; private $aPassword; private $aToken;
/** * Constructs the connection class, and obtains a valid Hi5AuthToken * * @param string $aKey The API_Key each application has when its created * @param string $aUsername Username of the developer of the app * @param string $aPassword Password of the developer of the app * */ public function __construct($aKey,$aUsername, $aPassword) { $this->sKey = $aKey; $this->aUsername = $aUsername; $this->aPassword = $aPassword;
$params = array( 'api_key' => $this->sKey, 'username' => $this->aUsername, 'password' => $this->aPassword ); $this->aToken = $this->do_request($this->sServer."rest/auth/plain",$params, "POST", "xml"); }
/** * Obtains the profile of the specified user * * @param int $iUser A valid userid of the profile being requested * * @return array containing the user profile */ public function user($iUser) { $sQuery = $this->sServer.'json/profile/user/'.$iUser; return $this->do_request($sQuery, array('Hi5AuthToken'=>$this->aToken), "GET", "json"); }
/** * Obtains the friends of the specified user * * @param int $iUser UserID of the person who's friends are requested * * @return array contining the list of friends or $iUser */ public function friends($iUser) { $sQuery = $this->sServer.'json/profile/foaf/'.$iUser; return $this->do_request($sQuery, array('Hi5AuthToken'=>$this->aToken), "GET", "json"); }
/** * Sends either a "GET", or "POST" request along with the specified parameters * * @param string $sQuery UserID of the person who's friends are requested * @param array $data Array containing the parameters for the "GET" or "POST" * request where $key=>$val in the array map to ?var=val * respectively in the "GET" or "POST" request. * @param string $post "GET" or "POST * @param string $json "json" or "xml" indicating the type of response that * is returned from the request * * @return array containing the result of the query */ public function do_request($sQuery, $data, $post, $json){ $parameter_string = $this->create_parameter_string($data);
if (strtoupper($post) == "POST"){//do post $context = array("http" => array("method" => "POST", "header" => "Content-type: application/x-www-form-urlencoded\r\n". "Content-length: " . strlen($parameter_string), "content" => $parameter_string)); $contextid=stream_context_create($context); $sock=fopen($sQuery, 'r', false, $contextid); }else{//do get $sQuery .= "?$parameter_string"; $sock=fopen($sQuery, 'r', false); } if ($sock) { $result=''; while (!feof($sock)) $result.=fgets($sock, 4096);
fclose($sock); }
if (strtolower($json) == "json"){ $hResult = json_decode($result); }else{ $oXML = @simplexml_load_string($result); // Warnings for "invalid" xmlns $hResult = self::convert_simplexml_to_array($oXML); } return $hResult; }
/** * creates an http-style parameter string from the given array * * @param array $params Array containing the parameters for the "GET" or "POST" * request where $key=>$val in the array map to ?var=val * respectively in the "GET" or "POST" request. * * @return string containing the http-style parameter string */ public function create_parameter_string($params) { $post_params = array();
foreach($params as $key=>$val) { if (is_array($val)) $val = implode(',', $val); $post_params[] = $key.'='.urlencode($val); } return implode('&', $post_params); }
/** * converts the given xml string to an array * * @param string $sxml XML string to be converted to an array * * @return array converted from the XML string */ public static function convert_simplexml_to_array($sxml) { $arr = array(); if ($sxml) { foreach ($sxml as $k => $v) { if ($sxml['count']) { $arr[] = self::convert_simplexml_to_array($v); } else { $arr[$k] = self::convert_simplexml_to_array($v); } } } if (sizeof($arr) > 0) { return $arr; } else { return (string)$sxml; } } } ?>
|
Dec 17, 2008
11:09 AM
|
|
The source got all screwed up in index.php, to see it clearly, in firefox, you can high-light the post, right click, and select "View Selection Source". That will show you the formatted source.
|
Dec 17, 2008
11:19 AM
|
|
Hi,
I want to get the status and using following function in the above mentioned class
public function getStatus($iUser) { $sQuery = $this->sServer.'json/status/getStatus'; return $this->do_request($sQuery, array('Hi5AuthToken'=>$this->aToken), "GET", "json"); }
and getting error:
Warning: fopen(http://api.hi5.com/json/status/getStatus?Hi5AuthToken=SkiyD0pIsg8a5LejAQAAAA..%3AjbfjRSyiEGDcyF5cchEdjkF91tyIg4eVHNK1XAA0saECA7sclMs-_iiDEXljtwgbcFBjNikNZqQ9G5EkS4gDSRpCJBeQDk3LPCDUDclAsp4.) [function.fopen]: failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error in E:\wwwroot\yash\statusUpdater\hi5\index.php on line 88
Please let me know the solution
Thanks
|
Jun 29
10:22 PM
|