php 使用 NP-Gravatar 获取 Gravatar 上的头像
使用 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
- 上一篇:php share一段采集程序的代码
- 下一篇:php 备份数据库为SQL文件
精彩图集
精彩文章






