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
- How can I programmatically check if a Google User’s profile picture isn’t default?
- HTTP POST and GET using cURL in Linux [duplicate]
- 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)
- What’s the net::ERR_HTTP2_PROTOCOL_ERROR about?
- How to use Python to execute a cURL command?
- How to define the basic HTTP authentication using cURL correctly?
- How to display request headers with command line curl
- cURL to show response headers after submiting a file
- Call to undefined function curl_init().?
- wget/curl large file from google drive
- cURL error 60: SSL certificate: unable to get local issuer certificate
- How do I make curl ignore the proxy?
- What exactly is cacert.pem for?
- tar: Unrecognized archive format error when trying to unpack flower_photos.tgz, TF tutorials on OSX
- SSL CA cert (path? access rights?)
- PHP cURL custom headers
- Error:error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure
- Setting Curl’s Timeout in PHP
- How to disable cURL SSL certificate verification
- curl: no URL specified for restful api
- How to read a CSV file from a URL with Python?
- cURL 28 error after switch from to brew php 7.2 on localhost
- Send data to 3rd party api with wp_remote_post on wp_login
- Passing .pem and .key files in cURL doesn’t work in WordPress
- Creating a post with the REST API, curl and oauth returning 401 error
- Share buttons on article footer
- wp_remote_get() to get AJAX url /wp-admin/admin-ajax.php
- Edit Custom Links Menu markup: Making a Social Media Menu with linkable icons
- Is curl required?
- How to set charset for wp_remote_post request?
- Is it possible to integrate WordPress *posts* and social media (Facebook, Google+, Twitter)? [closed]
- API getting null values with wp_remote_post
- Remote login with only the username not working
- WordPress wp_remote_post vs wp_remote_request
- Simple plugins to post info about new blog entries?
- Upload to a remote server using wp_remote_post
- Is it possible to use Twitter intents with the post’s image in WordPress?
- Automatically add simple custom buttons for print, Facebook share, & Tweet in Posts [closed]
- Add share links to all blog posts on homepage
- Programmatic Login from 3rd Party site
- Sending post request with wp_remote_post not working correctly
- Sharing images to social media – issue with aspect ratio
- wp_remote_post – handling responses
- Modify foreach loop for social sharing links?
- Curl requests sent two times
- Can i Use own Facebook App ID with this Social Comment Plugin? [closed]
- WordPress from url get external source title
- Download file using cURL into wp-includes/uploads
- curl problem or permalinks
- Using PODS data with save_post
- http_response_timeout filter not working
- facebook like, tweet and google+1 buttons inside the loop on home, archive and search pages and missing facebook like buttons
- Get single item from cURL plugin API call inside bash [closed]
- Uploading a media item with the wp-json API to a specific path
- How To Post WordPress Custom Post Types to Twitter via IFTTT
- Social sharing is not working as expected
- Use WordPress user database in external php application
- Keeping social share count after changing WordPress Permalinks
- How to share post?
- Error: Can´t access facebook comment plugin admin page
- Followers for WordPress [duplicate]
- Featured image for social sharing ot author archive page
- Post content in wp_remote_post
- Limit the number of external API calls per second
- WP Refused to display ‘URL’ in a frame because it set ‘X-Frame-Options’ to ‘sameorigin’
- Installation failed: 504 – Gateway Timeout
- How to add extra custom social icons to page with same style?
- Hide response returned from WordPress REST API call
- Update products with curl (bash)
- Installation problem with wordpress xampp
- how can I easily clear the “header is malformed” error when trying to reconnect social accounts in jetpack
- Facebook Share Permalink Javascript href
- Social sharing plugin directing to blank page after post sharing
- Is it better to set social media sharer in entry-footer.php or comments.php in WordPress blog?
- Post to a server writen in Hapijs from wordpress using wp_remote_post
- Sending WordPress database information to cross domain the safe way?
- Run WordPress Plugin in the Specified time
- Facebook and Google+ sharing suddenly stopped working properly in WordPress
- Get full page HTML for a non-public WordPress page
- how can i display share images for each article?
- Post sharing in social network
- how to get confirm that a shared user are inivited by member of website?
- What is the best way to change share image for social networks? [closed]
- How to use the HTTP API (wp_remote_get) instead of cURL?
- rest_cannot_create_user – Sorry, you are not allowed to create new users. CURL WORDPRESS REST API
- cURL External API request displays content above other content on page
- upload image with rest API to the media library