搜尋
首頁後端開發php教程使用 NP-Gravatar 取得 Gravatar 上的頭像

  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 '使用 NP-Gravatar 取得 Gravatar 上的頭像
    ';
  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 be 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 will allways be returned when using
  28. //that response format:
  29. $response = $gravatarService->getProfileInfo('foo@bar.com');
  30. echo $response->getHeader('Content-type'); //Prints "image/png".
复制代码
  1. //Gravatar XML-RPC implementation requires API key for the
  2. //authentication proccess. It can be retrieved on the page
  3. //for editing profile, 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's 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 have 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 be a user image for the current account.
  25. $this->_gravatarXmlRpc->saveData('path/to/someImage.jpg', NP_Service_Gravatar_XmlRpc::PG_RATED);
复制代码
  1. //Generating Gravatar URL.
  2. echo '使用 NP-Gravatar 取得 Gravatar 上的頭像;
  3. //Generating Gravatar URL and specifying size and rating options.
  4. echo '使用 NP-Gravatar 取得 Gravatar 上的頭像;
  5. //Full parameter names are supported, too.
  6. echo '使用 NP-Gravatar 取得 Gravatar 上的頭像;
  7. //Generating Gravatar URL and specifying file-type extension.
  8. echo '使用 NP-Gravatar 取得 Gravatar 上的頭像;
  9. //Above view helper call will produce this URL:
  10. //http://www.gravatar.com/avatar/f3ada405ce890b6f8204094deb12d8a8.jpg?s=200
复制代码


陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
高流量網站的PHP性能調整高流量網站的PHP性能調整May 14, 2025 am 12:13 AM

TheSecretTokeEpingAphp-PowerEdwebSiterUnningSmoothlyShyunderHeavyLoadInVolvOLVOLVOLDEVERSALKEYSTRATICES:1)emplactopCodeCachingWithOpcachingWithOpCacheToreCescriptexecution Time,2)使用atabasequercachingCachingCachingWithRedataBasEndataBaseLeSendataBaseLoad,3)

PHP中的依賴注入:初學者的代碼示例PHP中的依賴注入:初學者的代碼示例May 14, 2025 am 12:08 AM

你應該關心DependencyInjection(DI),因為它能讓你的代碼更清晰、更易維護。 1)DI通過解耦類,使其更模塊化,2)提高了測試的便捷性和代碼的靈活性,3)使用DI容器可以管理複雜的依賴關係,但要注意性能影響和循環依賴問題,4)最佳實踐是依賴於抽象接口,實現鬆散耦合。

PHP性能:是否可以優化應用程序?PHP性能:是否可以優化應用程序?May 14, 2025 am 12:04 AM

是的,優化papplicationispossibleandessential.1)empartcachingingcachingusedapcutorediucedsatabaseload.2)優化的atabaseswithexing,高效Quereteries,and ConconnectionPooling.3)EnhanceCodeWithBuilt-unctions,避免使用,避免使用ingglobalalairaiables,並避免使用

PHP性能優化:最終指南PHP性能優化:最終指南May 14, 2025 am 12:02 AM

theKeyStrategiestosigantificallyBoostPhpaPplicationPerformenCeare:1)UseOpCodeCachingLikeLikeLikeLikeLikeCacheToreDuceExecutiontime,2)優化AtabaseInteractionswithPreparedStateTementStatementStatementAndProperIndexing,3)配置

PHP依賴注入容器:快速啟動PHP依賴注入容器:快速啟動May 13, 2025 am 12:11 AM

aphpdepentioncontiveContainerIsatoolThatManagesClassDeptions,增強codemodocultion,可驗證性和Maintainability.itactsasaceCentralHubForeatingingIndections,因此reducingTightCightTightCoupOulplingIndeSingantInting。

PHP中的依賴注入與服務定位器PHP中的依賴注入與服務定位器May 13, 2025 am 12:10 AM

選擇DependencyInjection(DI)用於大型應用,ServiceLocator適合小型項目或原型。 1)DI通過構造函數注入依賴,提高代碼的測試性和模塊化。 2)ServiceLocator通過中心註冊獲取服務,方便但可能導致代碼耦合度增加。

PHP性能優化策略。PHP性能優化策略。May 13, 2025 am 12:06 AM

phpapplicationscanbeoptimizedForsPeedAndeffificeby:1)啟用cacheInphp.ini,2)使用preparedStatatementSwithPdoforDatabasequesies,3)3)替換loopswitharray_filtaray_filteraray_maparray_mapfordataprocrocessing,4)conformentnginxasaseproxy,5)

PHP電子郵件驗證:確保正確發送電子郵件PHP電子郵件驗證:確保正確發送電子郵件May 13, 2025 am 12:06 AM

phpemailvalidation invoLvesthreesteps:1)格式化進行regulareXpressecthemailFormat; 2)dnsvalidationtoshethedomainhasavalidmxrecord; 3)

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版

MantisBT

MantisBT

Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

將Eclipse與SAP NetWeaver應用伺服器整合。

VSCode Windows 64位元 下載

VSCode Windows 64位元 下載

微軟推出的免費、功能強大的一款IDE編輯器