通过AJAX(隐藏API)获取谷歌+1页股 [英] Getting google +1 Page shares via AJAX (hidden Api)
问题描述
在努力寻找获取在谷歌加页+1 通过jQuery的解决方案 - 阿贾克斯从谷歌的隐藏API:的 https://clients6.google.com/rpc
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
这问题也讨论了:<一href="http://stackoverflow.com/questions/13424640/getting-google-subscription-count-with-jquery">Stackoverflow链接
我的尝试:
$.ajax({
cache: false,
type: "POST",
url: "https://clients6.google.com/rpc",
data: [{
"method":"pos.plusones.get",
"id":"p",
"params":{
"nolog":true,
"id":"http://www.apple.com",
//"id":"http%3A%2F%2Fwww.apple.com",
"source":"widget",
"userId":"@viewer",
"groupId":"@self"
},
"jsonrpc":"2.0",
"key":"p",
"apiVersion":"v1"
}],
crossDomain: true,
jsonp: true,
timeout: 5000,
dataType: "jsonp",
contentType: "application/json; charset=utf-8",
success: function (data) {
console.log(data);
},
always: function(data){
console.log(data);
}
});
使用导致铬:未捕获的SyntaxError:意外的标记:
With result in chrome: Uncaught SyntaxError: Unexpected token :
和在Firefox: 语法错误:缺少;语句之前
And in Firefox: SyntaxError: missing ; before statement
{错误:{code: - 32700,消息:解析错误,数据:[{域:G
{"error":{"code":-32700,"message":"Parse Error","data":[{"domain":"g
任何想法如何解决这个问题?
推荐答案
您可以使用谷歌加JavaScript库,以获得股数:
You can use the google plus javascript library to get the share count:
包括以下:
<script src="https://apis.google.com/js/plusone.js"></script>
<script src="https://apis.google.com/js/client:plusone.js"></script>
然后执行:
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)
});
不要用自己的替换apikey。如果你这样做是行不通的。
Don't replace the apikey with your own. If you do it won't work.
这篇关于通过AJAX(隐藏API)获取谷歌+1页股的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!