获取Google+;使用'计数/共享;获取';方法通过Javascript

获取Google+;使用'计数/共享;获取';方法通过Javascript,javascript,google-plus,social,Javascript,Google Plus,Social,如何使用“get”通过Javascript(作为整数)获取Google+计数的数量 例如,在twitter中,我们可以通过URL获得: “+url 对于Google+共享,我发现我们可以使用Google+获得整个g+图标和共享数量 网址 此外,我还发现了一种通过发出AJAX请求来获取G+计数数的方法 如何通过“get”将其作为数字值获取。我强烈建议不要像您这样使用原始API查询。生成一个简单的API密钥,可以访问上的Google+API 您可以从给定的URL找到帖子,并获得如下活动详细信息,请注

如何使用“get”通过Javascript(作为整数)获取Google+计数的数量

例如,在twitter中,我们可以通过URL获得: “+url

对于Google+共享,我发现我们可以使用Google+获得整个g+图标和共享数量 网址

此外,我还发现了一种通过发出AJAX请求来获取G+计数数的方法


如何通过“get”将其作为数字值获取。我强烈建议不要像您这样使用原始API查询。生成一个简单的API密钥,可以访问上的Google+API

您可以从给定的URL找到帖子,并获得如下活动详细信息,请注意,我使用的是:

/**
*执行API查询以进行搜索,
*
*@param{String}searchUrl包含用于搜索的用户ID的Url。
*@param{int}queryCount进行的API调用数。
*@param{String}nextPageToken分页api调用的下一页标记。
*/
函数searchForUrl(searchUrl、queryCount、nextPageToken){
var userId=searchUrl.split('/')[3];
gapi.client.plus.activities.list({userId:userId,
pageToken:nextPageToken}).execute(函数(resp){
手工活动(分别为项目、搜索URL、查询计数、分别为下一个GetOken);
});
}
/**
*解析和存储XMLHttpRequest中的活动
*
*@param{Object}activities将响应活动对象作为数组。
*@param{String}设置帖子的URL。
*@param{int}queryCount API调用的数量。
*@param{string}nextPageToken下一页标记。
*/
功能处理活动(活动、姿势、查询计数、下一个GetOken){
for(活动中的var活动){
活动=活动[活动];
if(活动['url']==postrl){
目标活动=活动;
document.getElementById('result')。值='ID为:'+
activity.id+“\n”+
'PlusCount为:'+activity.object.plusoners.totalItems+'\n'+
'答复为:'+activity.object.Replies.totalItems+'\n'+
'重新共享为:'+activity.object.resharers.totalItems+'\n';
isFound=true;
}否则{
console.log(活动);
}
}
if(queryCount

进行演示非常感谢您的回复,这非常有帮助,但是,我实际上正在寻找一种方法来提供URL而不是用户ID,以便返回共享计数,是否可以查询gapi并返回链接共享计数?是的,您也可以这样做,但这有点棘手。。。。检查这里的代码:我会在有机会时更新我的答案。
/**
 * Performs the API queries for searching,
 *
 * @param {String} searchUrl The Url containing the user ID for searching.
 * @param {int} queryCount The number of API calls made.
 * @param {String} nextPageToken The next page token for paged api calls.
 */
function searchForUrl(searchUrl, queryCount, nextPageToken){
  var userId = searchUrl.split('/')[3];

  gapi.client.plus.activities.list({userId: userId,
      pageToken: nextPageToken}).execute( function(resp){
        handleActivities(resp.items, searchUrl, queryCount, resp.nextPageToken);
      });
}


/**
 * Parses and stores activities from the XMLHttpRequest
 *
 * @param {Object} activities The response activity objects as an array.
 * @param {String} postUrl The URL of the post.
 * @param {int} queryCount The number of API calls.
 * @param {string} nextPageToken The next page token.
 */
function handleActivities(activities, postUrl, queryCount, nextPageToken){
  for (var activity in activities){
    activity = activities[activity];
    if (activity['url'] == postUrl){
      targetActivity = activity;
      document.getElementById('result').value = 'ID is: ' +
          activity.id + '\n' +
          'PlusCount is: ' + activity.object.plusoners.totalItems + '\n' +
          'Replies are: ' + activity.object.replies.totalItems + '\n' +
          'Reshares are: ' + activity.object.resharers.totalItems + '\n';
      isFound = true;
    }else{
      console.log(activity);
    }
  }

  if (queryCount < maxQueryCount && !isFound){
    queryCount++;

    // throttle calls using timer to avoid reaching query limit
    console.log('retrying with ' + nextPageToken);
    setTimeout(searchForUrl(postUrl, queryCount, nextPageToken), 100);
  }
}