WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I've spent most of my morning working on my website's customized social share buttons. Reading out Twitter and Facebook shares were no problem, but Google Plus is a real challenge, as they don't offer an easy-to-use GET API.

I found a working technique using barebones CURL ( http://www.tomanthony.co.uk/blog/google_plus_one_button_seo_count_api/comment-page-1/ ). But previously, I've tried hard to get it to work with Wordpress' functions like wp_remote_post and failed. Anyone can tell me what I've been doing wrong?

Here is what I managed to get together. Two different requests fail:

$google_url = 'https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ';
$headers    = array('Content-type' => 'application/json');
$body       = array( "method"   => "pos.plusones.get"
                    ,"id"       => "p"
                    ,"params"   => array(   "nolog"     => true
                                            ,"id"       => $url
                                            ,"source"   => "widget"
                                            ,"userId"   => "@viewer"
                                            ,"groupId"  => "@self"
                    ,"jsonrpc"  =>"2.0"
                    ,"key"      => "p"
                    ,"apiVersion" => "v1"

$response = wp_remote_post( $google_url , array( 'method'   => 'POST'
                                                ,'headers'  => $headers
                                                ,'body'     => $body    ) );

if (!is_wp_error($response)) {
    $resp = json_decode($response['body'],true);
// Another attempt to get data with WP_Http 
$request = new WP_Http;
$result = $request->request( $google_url , array( 'method' => 'POST', 'body' => $body, 'headers' => $headers ) );

if (!is_wp_error($result)) {
    $resp = json_decode($result['body'],true);
    _e('error AGAIN');

PS: The API key is a public one for developers.

share|improve this question

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',
    '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);

   echo intval($json[0]['result']['metadata']['globalCounts']['count']);

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.