Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Retrieving Google Plus share count with wp_remote_post

I see that the question is 2 years old, but I worked hard two days to find solution of the very same problem and here is my code (for me works 100%).

$json_string = wp_remote_request('https://clients6.google.com/rpc',
array(
    'method'    => 'POST',
    'body'      => '[{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"'.rawurldecode(get_permalink()).'","source":"widget","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]',
    'headers' => array('Content-Type' => 'application/json')
));

$json = json_decode($json_string['body'], true);



if(isset($json[0]['result']['metadata']['globalCounts']['count'])){
   echo intval($json[0]['result']['metadata']['globalCounts']['count']);
}else{
   echo'0';
}

The big difference from the code above is that I send request in JSON format, not as an array.

Related Posts:

  1. HTTP request on localhost failing
  2. How can I use CURLOPT_USERPWD in wp_remote_post?
  3. On Plugin Activation, How Do I Check for Proper Transport Mechanism?
  4. cURL RETURNTRANSFER function in wp_remote_post
  5. How to convert this cURL to wp_remote_*?
  6. How to send file by wp_remote_post?
  7. How to send a HTTP Post request using PHP Curl and WordPress
  8. Inconsistencies between wp_remote_post and cURL
  9. Does wp_remote_post() require curl?
  10. Add Google+ Badge to Posts – Specific to Author
  11. wp_remote_post vs curl to send data in WordPress plugin
  12. JSONDecodeError: Expecting value: line 1 column 1 (char 0)
  13. curl: (60) SSL certificate problem: unable to get local issuer certificate
  14. JSONDecodeError: Expecting value: line 1 column 1 (char 0)
  15. Is there a way to follow redirects with command line cURL?
  16. How to use Python to execute a cURL command?
  17. How can I set the request header for curl?
  18. How to use Python to execute a cURL command?
  19. How to use the curl command in PowerShell?
  20. How to capture cURL output to a file?
  21. How to use cURL to send Cookies?
  22. CURL ERROR: Recv failure: Connection reset by peer – PHP Curl
  23. curl: (35) SSL connect error
  24. curl POST format for CURLOPT_POSTFIELDS
  25. tar: Unrecognized archive format error when trying to unpack flower_photos.tgz, TF tutorials on OSX
  26. HTTP Error 411, The request must be chunked or have a content length
  27. Curl not recognized as an internal or external command, operable program or batch file
  28. PHP cURL HTTP PUT
  29. How to disable cURL SSL certificate verification
  30. Getting error in Curl – Peer certificate cannot be authenticated with known CA certificates
  31. cURL equivalent in Node.js?
  32. Run Rsync from Python [duplicate]
  33. whats the meaning of curl “-s” and “-m”
  34. Storing posts social counters by using transient api
  35. Default image for homepage when shared in social media
  36. wp_remote_get vs. file_get_contents vs. cURL?
  37. Is there a plugin that pushes posts to your Google+ profile?
  38. Share buttons on article footer
  39. wp_remote_get() to get AJAX url /wp-admin/admin-ajax.php
  40. How can i disable a plugin for a mobile phone?
  41. How to automate filing a form as a user
  42. WordPress API returns empty page when page is less than X-WP-TotalPages
  43. Create a WordPress post using curl comand from Linux console?
  44. cURL – How to send and fetch data in WordPress
  45. Is there a way to change a post’s thumbnail image(s)?
  46. Only display link to author social media when it exists [closed]
  47. Creating login session via CURL
  48. File Type Is Not Permitted – Cronjob
  49. Download failed cURL error 7: . Can’t update anything
  50. creating form for wp_remote_post
  51. Where Does WordPress Make cURL Requests? How To Add cURL Option
  52. How to have a “clean” post content, for excerpt and social networks sharing
  53. export a csv file from the database with a cronjob
  54. How to create a post using REST API with sending data as a JSON body?
  55. WordPress curl timing out and saying ‘Moved Permanently’
  56. LinkedIn Social Wall | Is there a plug-in (Free / Paid) to display a LinkedIn feed in a social wall (not just a feed)?
  57. How to create custom post by using REST API securely?
  58. PHP to Handle API Return instead of print
  59. wp_remote_post – handling responses
  60. Modify foreach loop for social sharing links?
  61. How to integrate Facebook Share button without code?
  62. get post content of particular post by url
  63. Why is json_decode failing?
  64. How to add FB like + share AND also other Social Buttons on ALL pages and posts?
  65. Is there a WordPress plugin that can post to Google+? [closed]
  66. Publish page remotely
  67. Update File Once Every 30 Days
  68. No post image when pasting link into Facebook
  69. how to set social icons to product / post template (Auros theme)? [closed]
  70. wp_remote_post empty $_POST
  71. cURL error for cron
  72. How to send the body in wp_remote_post as “raw”?
  73. WordPress transient not working with WP Engine
  74. Generate new post from email
  75. SOAP Request/Parsing XML From wp_send_json_success
  76. Accessing an API with jQuery and AJAX
  77. Social share buttons text shows up on post excerpts
  78. How to create social Share Buttons Without Plugin
  79. Simulating timeout is not working
  80. Are there any Inbuilt Social media sharing icons
  81. wp_remote_post code conversion
  82. Author social media aren’t shown on the page
  83. Send POST request to Flask app from functions.php file
  84. WordPress Sumo Plugin not showing all images on clicking pinterest icon
  85. Add Flatr button to Sharing option
  86. Google + auto post publish
  87. wordpress database error
  88. Share buttons in some specific posts in WordPress
  89. Encode URL picked up by Digg Digg
  90. Is it possible to make WordPress as a RESTful app?
  91. Social Sharing / tell a friend plug but specify which URL to share
  92. Does a Google + RSS Plugin Exist?
  93. Facebook share button only share the_permalink(), without thumbnail, tilte, excerpt, etc
  94. How do I remove social buttons from the “Blog” section of my theme?
  95. How to test a HTTPS URL with a given IP address
  96. Difference between `curl -I` and `curl -X HEAD`
  97. Send post to remote wp site from post edit window with all data excerpt image
  98. Using wp_mail to send attachment from a file stream content
  99. Convert HTTP_Request2 to wp_remote_post
  100. how to send csv file to other server using wp_remote_post?
Categories google-plus Tags curl, google-plus, social-sharing, wp-remote-post
Adding Multiple Values to a Post Meta Key
Add a term to an attachment submitted from front end

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress