使用 NP-Gravatar 获取 Gravatar 上的头像
Lepaskan: 2016-07-25 09:11:19
asal
1077 orang telah melayarinya
- //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 . '
';
- echo 'Username: ' . $profile->getPreferredUsername() . '
';
-
- echo 'Photos:
';
- foreach($profile->getPhotos() as $photo) {
- echo '
';
- }
-
- //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".
复制代码
- //Gravatar XML-RPC implementation requires API key for the
- //authentication proccess. It can be retrieved on the page
- //for editing profile, on wordpress.com.
- $apiKey = 'someAPIKey';
- $email = 'foo.bar@foobar.com'; //Email address associated with the $apiKey.
- //Creating instance:
- $gravatarXmlRpc = new NP_Service_Gravatar_XmlRpc($apiKey, $email);
-
- //Checking whether there's a gravatar account registered with supplied email addresses.
- $result = $gravatarXmlRpc->exists(array(
- 'posa.nikola@gmail.com', //That's me. :D
- 'foo@example.com'
- ));
- $values = array_values($result);
- echo (bool)$values[0]; //Prints "true", as I do have Gravatar account. :)
- echo (bool)$values[1]; //Prints "false", as that second email address probably doesn't exist.
-
- //Getting user images on the current account:
- $images = $gravatarXmlRpc->userImages();
- //$image is instance of NP_Service_Gravatar_XmlRpc_UserImage,
- //as we didn't pass $raw parameter as "true" when executing
- //userImages() method.
- $image = $images[0];
- $imageUrl = $image->getUrl(); //Instance of Zend_Uri_Http.
- echo $image->getRating(); //Prints some rating (G, PG, R or X).
-
- //Saves some image to be a user image for the current account.
- $this->_gravatarXmlRpc->saveData('path/to/someImage.jpg', NP_Service_Gravatar_XmlRpc::PG_RATED);
复制代码
- //Generating Gravatar URL.
- echo ';
-
- //Generating Gravatar URL and specifying size and rating options.
- echo ';
- //Full parameter names are supported, too.
- echo ';
-
- //Generating Gravatar URL and specifying file-type extension.
- echo ';
- //Above view helper call will produce this URL:
- //http://www.gravatar.com/avatar/f3ada405ce890b6f8204094deb12d8a8.jpg?s=200
复制代码
|
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Artikel terbaru oleh pengarang
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31
Topik-topik yang berkaitan
Lagi>