龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

php 使用 NP-Gravatar 获取 Gravatar 上的头像

时间:2014-07-29 02:37来源:网络整理 作者:网络 点击:
分享到:
使用 NP-Gravatar 获取 Gravatar 上的头像 [代码片段(35行)]
//Creating instance:
$gravatarService = new NP_Service_Gravatar_Profiles();
//Changing response format to XML:
$gravatarService->setResponseFormat(new NP_Service_Gravatar_Profiles_ResponseFormat_Xml());

//Getting profile data.
$profile = $gravatarService->getProfileInfo('foo@bar.com');
//$profile is instance of NP_Gravatar_Profile so we can access some of its properties.
echo 'ID: ' . $profile->id . '<br />';
echo 'Username: ' . $profile->getPreferredUsername() . '<br /><br />';

echo 'Photos: <br />';
foreach($profile->getPhotos() as $photo) {
   echo '<img src="' . $photo->value . '" /> <br />';
}

//Changing response format to JSON:
$gravatarService->setResponseFormat(new NP_Service_Gravatar_Profiles_ResponseFormat_Json());
//Getting profile data but forcing raw Zend_Http_Response object to be returned, 
//by passing boolean true for the second argument of the getProfileInfo() method:
$response = $gravatarService->getProfileInfo('foo@bar.com', true);
if ($response instanceof Zend_Http_Response) { //true!
   //do something
}

//Changing response format to QR Code:
$gravatarService->setResponseFormat(new NP_Service_Gravatar_Profiles_ResponseFormat_QRCode());
//QR Code response can not be exported NP_Gravatar_Profile object, as that 
//response format type does not implement 
//NP_Service_Gravatar_Profiles_ResponseFormat_ParserInterface interface, 
//so raw Zend_Http_Response object will allways be returned when using 
//that response format:
$response = $gravatarService->getProfileInfo('foo@bar.com');
echo $response->getHeader('Content-type'); //Prints "image/png".
//该片段来自于http://outofmemory.cn
精彩图集

赞助商链接