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. register_rest_route, Compare purchase codes and send a response
  13. How can I programmatically check if a Google User’s profile picture isn’t default?
  14. How do I get a YouTube video thumbnail from the YouTube API?
  15. How do I POST JSON data with cURL?
  16. What’s the net::ERR_HTTP2_PROTOCOL_ERROR about?
  17. JSONDecodeError: Expecting value: line 1 column 1 (char 0)
  18. curl: (60) SSL certificate problem: unable to get local issuer certificate
  19. HTTP POST and GET using cURL in Linux [duplicate]
  20. How do I POST JSON data with cURL?
  21. curl: (60) SSL certificate problem: unable to get local issuer certificate
  22. JSONDecodeError: Expecting value: line 1 column 1 (char 0)
  23. How do I install and use cURL on Windows?
  24. Is there a way to follow redirects with command line cURL?
  25. JSONDecodeError: Expecting value: line 1 column 1 (char 0)
  26. How to fix “SSL certificate problem: self signed certificate in certificate chain” error?
  27. How to send a header using a HTTP request through a cURL call?
  28. How to use Python to execute a cURL command?
  29. What’s the net::ERR_HTTP2_PROTOCOL_ERROR about?
  30. How can I set the request header for curl?
  31. How to use Python to execute a cURL command?
  32. How to define the basic HTTP authentication using cURL correctly?
  33. How to use the curl command in PowerShell?
  34. https connection using CURL from command line
  35. performing HTTP requests with cURL (using PROXY)
  36. How to define the basic HTTP authentication using cURL correctly?
  37. Curl command for https ( SSL )
  38. How to do a PUT request with cURL?
  39. How to display request headers with command line curl
  40. How to capture cURL output to a file?
  41. Using cURL with a username and password?
  42. PHP + curl, HTTP POST sample code?
  43. What is the curl error 52 “empty reply from server”?
  44. How to fix libeay32.dll was not found error
  45. Can curl make a connection to any TCP ports, not just HTTP/HTTPS?
  46. cURL to show response headers after submiting a file
  47. curl: (6) Could not resolve host: google.com; Name or service not known
  48. Call to undefined function curl_init().?
  49. How do I get a YouTube video thumbnail from the YouTube API?
  50. How to use cURL to send Cookies?
  51. wget/curl large file from google drive
  52. How do I POST JSON data with cURL?
  53. CURL ERROR: Recv failure: Connection reset by peer – PHP Curl
  54. curl: (35) SSL connect error
  55. cURL error 60: SSL certificate: unable to get local issuer certificate
  56. Binary Data Posting with curl
  57. How do I make curl ignore the proxy?
  58. What exactly is cacert.pem for?
  59. curl POST format for CURLOPT_POSTFIELDS
  60. tar: Unrecognized archive format error when trying to unpack flower_photos.tgz, TF tutorials on OSX
  61. curl : (1) Protocol https not supported or disabled in libcurl
  62. SSL CA cert (path? access rights?)
  63. HTTP Error 411, The request must be chunked or have a content length
  64. Curl not recognized as an internal or external command, operable program or batch file
  65. PHP cURL custom headers
  66. How do I measure request and response times at once using cURL?
  67. PHP cURL HTTP PUT
  68. Why does cURL return error “(23) Failed writing body”?
  69. Curl : connection refused
  70. file_get_contents( ) not working
  71. Error:error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure
  72. Can PHP cURL retrieve response headers AND body in a single request?
  73. Setting Curl’s Timeout in PHP
  74. How to disable cURL SSL certificate verification
  75. Getting error in Curl – Peer certificate cannot be authenticated with known CA certificates
  76. How to POST JSON Data With PHP cURL?
  77. cURL request in Laravel
  78. curl: no URL specified for restful api
  79. Keep getting a “Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup” when attempting to google plus login on my web app
  80. curl: (60) Peer’s Certificate issuer is not recognized.
  81. cURL equivalent in Node.js?
  82. Curl Error 56 “Failure when receiving data from the peer” while sending .tar.gz File
  83. How to read a CSV file from a URL with Python?
  84. Run Rsync from Python [duplicate]
  85. whats the meaning of curl “-s” and “-m”
  86. Is it safe to use sslverify => true for with wp_remote_get/wp_remote_post
  87. How to use OAuth authentication with REST API via CURL commands?
  88. Sending JSON string through wp_remote_post()
  89. I found this in a plugin. What does it do? is it dangerous?
  90. Uploading media with the REST API
  91. How to add Request header in WordPress remote api calls
  92. cURL 28 error after switch from to brew php 7.2 on localhost
  93. Storing posts social counters by using transient api
  94. Error timed out with succesfull wp_remote_post
  95. Send data to 3rd party api with wp_remote_post on wp_login
  96. Wp_remote_post not posting data
  97. Difference between wp_remote_post and wp_safe_remote_post
  98. Re use authenticated HTTP connection or cUrl handle
  99. Log in from one wordpress website to another wordpress website
  100. Passing .pem and .key files in cURL doesn’t work in WordPress
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
  • Post Navigation Elementor
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • WPFacet multiple loop displaying duplicate content
  • Get the name of the template/*html file used
  • Fix: WordPress.DB.PreparedSQL.NotPrepared Plugin Check (PCP)
  • Removing unnecessary CSS and JS code from wp_head()
  • hexagonal image gallery. Am I on the right track? [closed]
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
© 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