Platon
Platon

Reputation: 495

How to get Google Plus share count in jQuery without API keys?

I know, how to make G+ counter with PHP. Also I know same solution with Google API key.

But I try to make that in my jQuery plugin (without any PHP classes or something else) and have no results..

Help with example code, please.

Upvotes: 1

Views: 2263

Answers (1)

Platon
Platon

Reputation: 495

This solution worked for me:

var uri = 'http://your-site.com';

$.ajax({
  type: 'POST',
  url: 'https://clients6.google.com/rpc',
  processData: true,
  contentType: 'application/json',
  data: JSON.stringify({
    'method': 'pos.plusones.get',
    'id': uri,
    'params': {
      'nolog': true,
      'id': uri,
      'source': 'widget',
      'userId': '@viewer',
      'groupId': '@self'
    },
    'jsonrpc': '2.0',
    'key': 'p',
    'apiVersion': 'v1'
  }),
  success: function(response) {
    $('a.googleplus .counter').text(response.result.metadata.globalCounts.count);
  }
});

Upvotes: 10

Related Questions