Use Np-gravatar to get the avatar on the Gravatar

Source: Internet
Author: User
<无详细内容>
  1. Creating instance:
  2. $gravatarService = new Np_service_gravatar_profiles ();
  3. Changing response format to XML:
  4. $gravatarService->setresponseformat (New Np_service_gravatar_profiles_responseformat_xml ());
  5. Getting profile data.
  6. $profile = $gravatarService->getprofileinfo (' foo@bar.com ');
  7. $profile is instance of Np_gravatar_profile so we can access some of its properties.
  8. Echo ' ID: '. $profile->id. '
    ';
  9. Echo ' Username: '. $profile->getpreferredusername (). '

    ';
  10. Echo ' Photos:
    ';
  11. foreach ($profile->getphotos () as $photo) {
  12. Echo ' value. ' "/>
    ';
  13. }
  14. Changing response format to JSON:
  15. $gravatarService->setresponseformat (New Np_service_gravatar_profiles_responseformat_json ());
  16. Getting profile data But forcing raw Zend_http_response object to be returned,
  17. By passing Boolean true for the second argument of the Getprofileinfo () method:
  18. $response = $gravatarService->getprofileinfo (' foo@bar.com ', true);
  19. if ($response instanceof zend_http_response) {//true!
  20. Do something
  21. }
  22. Changing response format to QR Code:
  23. $gravatarService->setresponseformat (New Np_service_gravatar_profiles_responseformat_qrcode ());
  24. QR Code response can not is exported Np_gravatar_profile object, as that
  25. Response format type does not implement
  26. Np_service_gravatar_profiles_responseformat_parserinterface interface,
  27. So raw Zend_http_response object would allways is returned when using
  28. That response format:
  29. $response = $gravatarService->getprofileinfo (' foo@bar.com ');
  30. echo $response->getheader (' Content-type '); Prints "Image/png".
Copy Code
  1. Gravatar XML-RPC implementation requires API key for the
  2. Authentication proccess. It can retrieved on the page
  3. For editing profiles, on WordPress.com.
  4. $apiKey = ' Someapikey ';
  5. $email = ' foo.bar@foobar.com '; Email address associated with the $apiKey.
  6. Creating instance:
  7. $GRAVATARXMLRPC = new Np_service_gravatar_xmlrpc ($apiKey, $email);
  8. Checking whether there ' a Gravatar account registered with supplied email addresses.
  9. $result = $gravatarXmlRpc->exists (Array (
  10. ' posa.nikola@gmail.com ',//that ' s me. :D
  11. ' Foo@example.com '
  12. ));
  13. $values = Array_values ($result);
  14. Echo (BOOL) $values [0]; Prints "true", as I do has Gravatar account. :)
  15. Echo (BOOL) $values [1]; Prints "false", as that second email address probably doesn ' t exist.
  16. Getting user images on the current account:
  17. $images = $gravatarXmlRpc->userimages ();
  18. $image is instance of Np_service_gravatar_xmlrpc_userimage,
  19. As we didn ' t pass $raw parameter as "true" when executing
  20. Userimages () method.
  21. $image = $images [0];
  22. $IMAGEURL = $image->geturl (); Instance of Zend_uri_http.
  23. echo $image->getrating (); Prints Some rating (G, PG, R or X).
  24. Saves some image to is a user image for the current account.
  25. $this->_gravatarxmlrpc->savedata (' path/to/someimage.jpg ', Np_service_gravatar_xmlrpc::P g_rated);
Copy Code
    1. Generating Gravatar URL.
    2. Echo ' Gravatar (' foo@bar.com '). ' "/>;
    3. Generating Gravatar URL and specifying size and rating options.
    4. Echo ' Gravatar (' foo@bar.com ', array (' s ' =>200, ' r ' = ' PG ')). ' "/>;
    5. Full parameter names is supported, too.
    6. Echo ' Gravatar (' foo@bar.com ', array (' Size ' =>100, ' default ' = ' Identicon ')). ' "/>;
    7. Generating Gravatar URL and specifying File-type extension.
    8. Echo ' Gravatar (' foo@bar.com ', array (' s ' =>200), ' jpg '). ' "/>;
    9. Above View Helper call would produce this URL:
    10. http://www.gravatar.com/avatar/f3ada405ce890b6f8204094deb12d8a8.jpg?s=200
Copy Code
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.