Struggling to find the solution for getting the Google Plus +1 of page via jQuery - Ajax from Google\'s hidden api: https://clients6.google.com/rpc
T
You should be using the official API for Google+ to get +1 counts for pages. The following example from the APIs explorer shows the API call and response data:
https://developers.google.com/apis-explorer/#p/plus/v1/plus.people.get?userId=%252BGooglePlusDevelopers&fields=plusOneCount&_h=2&
A short demo of how to use the API client library:
1) Async include of the Google+ client / Google API client library
<script type="text/javascript">
(function() {
var po = document.createElement('script');
po.type = 'text/javascript'; po.async = true;
po.src = 'https://plus.google.com/js/client:plusone.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(po, s);
})();
</script>
When the client loads, set the API key with a key from the Google APIs console:
gapi.client.setApiKey('YOUR_API_KEY')
Next, load the callback and place an API call once the client is loaded.
<script>
gapi.client.load('plus', 'v1',
function(){
gapi.client.plus.people.get(
{userId: '+GooglePlusDevelopers'}
).execute( function(resp){ console.log(resp); }
);
});
</script>
This will return JSON data that includes the +1 count, e.g.:
gapi.client.load('plus', 'v1',
function(){
gapi.client.plus.people.get(
{userId: '+GooglePlusDevelopers'}
).execute( function(resp){ console.log(resp.plusOneCount); }
);
});
Will return 225588, the count of +1s for the page.
You can use the google plus javascript library to get the share count:
Include these:
<script src="https://apis.google.com/js/plusone.js"></script>
<script src="https://apis.google.com/js/client:plusone.js"></script>
Then do:
var params = {
nolog: true,
id: "http://www.google.com/",
source: "widget",
userId: "@viewer",
groupId: "@self"
};
gapi.client.setApiKey('AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ')
gapi.client.rpcRequest('pos.plusones.get', 'v1', params).execute(function(resp) {
console.log('count:', resp.result.metadata.globalCounts.count)
});
Don't replace the apikey with your own. If you do it won't work.