R
R
Rokis2017-08-30 21:55:11
Google
Rokis, 2017-08-30 21:55:11

How to get the number of google+ reposts from a specific page of a site?

Hello.
There is a code for social buttons social like js:

plusone: {
                counterUrl: n + "//share.yandex.ru/gpp.xml?url={url}&callback=?",
                convertNumber: function(a) {
                    return parseInt(a.replace(/\D/g, ""), 10)
                }

Because of it (at this URL), a 500 error occurs and the page loads for a very long time. What URL can be used to get the number of reposts for the counter and how to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rokis, 2017-08-31
@Rokis

Replaced this code with:

var url = "http://www.yoursite-to-be-counted.com";
var data = {
    "method":"pos.plusones.get",
    "id": url,
    "params":{
        "nolog":true,
        "id": url,
        "source":"widget",
        "userId":"@viewer",
        "groupId":"@self"
    },
    "jsonrpc":"2.0",
    "key":"p",
    "apiVersion":"v1"
  };
  $.ajax({
    type: "POST",
    url: "https://clients6.google.com/rpc",
    processData: true,
    contentType: 'application/json',
    data: JSON.stringify(data),
    success: function(r){
      setCount($(".google-plus-count"), r.result.metadata.globalCounts.count);
    }
  });

  var setCount = function($item, count) {
    if (count) {
      $item.text(count);
    }
  };

And everything worked. You only need to put your URL and class.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question