问题
Is possible to get the total number of Google+ subscriptions in same way was done on http://www.tomanthony.co.uk/google_plus_one_api_example.php? Without php?
Thanks
update: i tried with this piece of code but isn't working
function getplusone(url){ var plusones; $.getJSON('https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ' + 'callback=?', { "method":"pos.plusones.get", "id":"p", "params":{ "nolog":true, "id":url, "source":"widget", "userId":"@viewer", "groupId":"@self" }, "jsonrpc":"2.0", "key":"p", "apiVersion":"v1" }, function(data){ plusones = data.count; $('#feed').html(plusones); }); }
回答1:
First you need to create a API Key from Google Console - https://console.developers.google.com
Then you need to get the Page or Profile Id for which you need to get the followers/subscribers count.
After that you need to send a request to this url- https://www.googleapis.com/plus/v1/people/{PROFILE_ID}?key={APIKEY}
Using the below code-
var profileid = 'YOUR_PROFILE_ID';
var apikey = 'YOUR_API_KEY';
var url = 'https://www.googleapis.com/plus/v1/people/' + profileid + '?key=' + apikey;
$.ajax({
type: "GET",
dataType: "json",
url: url,
success: function (data) {
var googlefollowcount = data.circledByCount;
$(".googlefollowercount").html(googlefollowcount);
}
});
The request will be send like this one above but make sure that you replace your Profile ID and API key.
You can see and follow the whole process from this url- http://www.bloggerever.com/2014/05/how-can-you-get-google-plus-follower.html
回答2:
The response data is usually represented in JSON format. Generally, you can receive the desired data through a server's API method, jQuery features an ability of sending such requests. It should look something like this
$.ajax({
cache: false,
type: "GET",
url: "https://example.org/method/getInformation",
data: { uid: "1232", fields: name,lastname,photo,subscriptions, access_token: "1224beca124"},
dataType: "jsonp",
success: function (result) {
console.log(result);
}
});
All the data is just for example. Note that if you send requests from your server to Google+'s server, you need to use attribute dataType: "jsonp", since it is a way that cross-domain requests are handled. Note also that you may or you may not need a token (granted through authentication system, like OAuth) for some kind of information.
回答3:
This should work:
$.ajax({
cache: false,
type: "POST",
url: "https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ",
data: [{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"http://www.test.com","source":"widget","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}],
dataType: "jsonp",
success: function (data) {
console.log(data);
},
error: function(data){
console.log(data);
}
});
It's the standard jQuery ajax request. You need dataType: "jsonp" because it's a cross-domain request, and you need type: "POST" as in the blog post from the example you provided. However, when I try it, it returns an object with state = "rejected" and I suppose this is because the key is no longer valid. If you have your own valid key it should work.
来源:https://stackoverflow.com/questions/13424640/getting-google-subscription-count-with-jquery