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:
- HTTP request on localhost failing
- How can I use CURLOPT_USERPWD in wp_remote_post?
- On Plugin Activation, How Do I Check for Proper Transport Mechanism?
- cURL RETURNTRANSFER function in wp_remote_post
- How to convert this cURL to wp_remote_*?
- How to send file by wp_remote_post?
- How to send a HTTP Post request using PHP Curl and WordPress
- Inconsistencies between wp_remote_post and cURL
- Does wp_remote_post() require curl?
- Add Google+ Badge to Posts – Specific to Author
- wp_remote_post vs curl to send data in WordPress plugin
- register_rest_route, Compare purchase codes and send a response
- How can I programmatically check if a Google User’s profile picture isn’t default?
- How do I get a YouTube video thumbnail from the YouTube API?
- How do I POST JSON data with cURL?
- What’s the net::ERR_HTTP2_PROTOCOL_ERROR about?
- JSONDecodeError: Expecting value: line 1 column 1 (char 0)
- curl: (60) SSL certificate problem: unable to get local issuer certificate
- HTTP POST and GET using cURL in Linux [duplicate]
- How do I POST JSON data with cURL?
- curl: (60) SSL certificate problem: unable to get local issuer certificate
- JSONDecodeError: Expecting value: line 1 column 1 (char 0)
- How do I install and use cURL on Windows?
- Is there a way to follow redirects with command line cURL?
- JSONDecodeError: Expecting value: line 1 column 1 (char 0)
- How to fix “SSL certificate problem: self signed certificate in certificate chain” error?
- How to send a header using a HTTP request through a cURL call?
- How to use Python to execute a cURL command?
- What’s the net::ERR_HTTP2_PROTOCOL_ERROR about?
- How can I set the request header for curl?
- How to use Python to execute a cURL command?
- How to define the basic HTTP authentication using cURL correctly?
- How to use the curl command in PowerShell?
- https connection using CURL from command line
- performing HTTP requests with cURL (using PROXY)
- How to define the basic HTTP authentication using cURL correctly?
- Curl command for https ( SSL )
- How to do a PUT request with cURL?
- How to display request headers with command line curl
- How to capture cURL output to a file?
- Using cURL with a username and password?
- PHP + curl, HTTP POST sample code?
- What is the curl error 52 “empty reply from server”?
- How to fix libeay32.dll was not found error
- Can curl make a connection to any TCP ports, not just HTTP/HTTPS?
- cURL to show response headers after submiting a file
- curl: (6) Could not resolve host: google.com; Name or service not known
- Call to undefined function curl_init().?
- How do I get a YouTube video thumbnail from the YouTube API?
- How to use cURL to send Cookies?
- wget/curl large file from google drive
- How do I POST JSON data with cURL?
- CURL ERROR: Recv failure: Connection reset by peer – PHP Curl
- curl: (35) SSL connect error
- cURL error 60: SSL certificate: unable to get local issuer certificate
- Binary Data Posting with curl
- How do I make curl ignore the proxy?
- What exactly is cacert.pem for?
- curl POST format for CURLOPT_POSTFIELDS
- tar: Unrecognized archive format error when trying to unpack flower_photos.tgz, TF tutorials on OSX
- curl : (1) Protocol https not supported or disabled in libcurl
- SSL CA cert (path? access rights?)
- HTTP Error 411, The request must be chunked or have a content length
- Curl not recognized as an internal or external command, operable program or batch file
- PHP cURL custom headers
- How do I measure request and response times at once using cURL?
- PHP cURL HTTP PUT
- Why does cURL return error “(23) Failed writing body”?
- Curl : connection refused
- file_get_contents( ) not working
- Error:error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure
- Can PHP cURL retrieve response headers AND body in a single request?
- Setting Curl’s Timeout in PHP
- How to disable cURL SSL certificate verification
- Getting error in Curl – Peer certificate cannot be authenticated with known CA certificates
- How to POST JSON Data With PHP cURL?
- cURL request in Laravel
- curl: no URL specified for restful api
- Keep getting a “Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup” when attempting to google plus login on my web app
- curl: (60) Peer’s Certificate issuer is not recognized.
- cURL equivalent in Node.js?
- Curl Error 56 “Failure when receiving data from the peer” while sending .tar.gz File
- How to read a CSV file from a URL with Python?
- Run Rsync from Python [duplicate]
- whats the meaning of curl “-s” and “-m”
- Is it safe to use sslverify => true for with wp_remote_get/wp_remote_post
- How to use OAuth authentication with REST API via CURL commands?
- Sending JSON string through wp_remote_post()
- I found this in a plugin. What does it do? is it dangerous?
- Uploading media with the REST API
- How to add Request header in WordPress remote api calls
- cURL 28 error after switch from to brew php 7.2 on localhost
- Storing posts social counters by using transient api
- Error timed out with succesfull wp_remote_post
- Send data to 3rd party api with wp_remote_post on wp_login
- Wp_remote_post not posting data
- Difference between wp_remote_post and wp_safe_remote_post
- Re use authenticated HTTP connection or cUrl handle
- Log in from one wordpress website to another wordpress website
- Passing .pem and .key files in cURL doesn’t work in WordPress