如何获得2.7版的Facebook共享计数和评论计数 [英] How to get Facebook Share Count and Comment Count on Version 2.7

查看:99
本文介绍了如何获得2.7版的Facebook共享计数和评论计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是什么?

使用我的php代码无法获得结果/输出吗?(首次发布)

Im not getting result/output, using my php code?(first issued)

如何在我的php代码上输入我的访问令牌? (第二期)

How to input my Access Token on my php code? (Second Issued)

当我从浏览器输入此URL时: https://graph.facebook.com/v2.1/?id=http://google.com

When i enter this URL from browser: https://graph.facebook.com/v2.1/?id=http://google.com

我正在获取结果JSON:

{
   "share": {
      "comment_count": 0,
      "share_count": 44100483
   },
   "og_object": {
      "id": "1485280808235339",
      "description": "Honoring our veterans #GoogleDoodle",
      "title": "Google",
      "type": "website",
      "updated_time": "2017-11-11T21:40:44+0000"
   },
   "id": "http://google.com"
}

但是,当我使用我的php代码时,我没有得到任何结果.

However, When I used my php code I'm not getting any result.

我下面的完整php代码:


        public function getFacebookData($domain)
        {
            try
            {
                $facebook_app_id = "666987483466439";
                $facebook_app_secret = "b3e1a0948513223b0bc51b32a735e2cf";
                $access_token = $facebook_app_id . '|' . $facebook_app_secret;
                $curl_response = $this->curl->get("http://graph.facebook.com/v2.7/?id=" . $domain . '&fields=share&access_token=' . $access_token);   //$curl_response = $this->curl->get("http://graph.facebook.com/v2.1/?id=" . $domain);

我的代码是否有问题或我错过了什么?预先感谢您的帮助人员!

Is there any problem with my code or something i missed?Thanks in advance for your help guys!

来自Facebook开发者网站文档:我需要在我的代码中输入访问令牌:Application ID|App Secret另一个问题.我在这里输入的Application ID|App Secret正在工作并经过测试.

From Facebook Developer Site Doc: I need to input an Access Token on my code: Application ID|App Secret another Issue. The Application ID|App Secret i input here is working and tested.

如何在我的php代码上输入我的token?

How to input my token on my php code?

推荐答案

我找到了解决方案,但在php中没有js

I found a solution, but not in php ruther is js

以下是有效代码:

$(function() {
      var url = "http://facebook.com";
      var apiUrl = "https://graph.facebook.com/?ids=" + url;
    
  $.ajax({
      url: apiUrl,
      success: function(result) {
  $.each(result, function(key, val) {
        console.log(key + " - " + val["share"]["share_count"]);
        console.log(key + " - " + val["share"]["comment_count"]);

            var commentCount = val["share"]["comment_count"];
            var shareCount = val["share"]["share_count"];
            $("#fb-like-div").html(shareCount);
            $("#fb-comment-div").html(commentCount);
          });
        }
      });
    });

#fb-like-div,#fb-comment-div{color:red;}

<script type="text/javascript" src="//code.jquery.com/jquery-1.12.4.js"></script>
<div id="fb-like-div">0</div>
<div id="fb-comment-div">0</div>
 

这篇关于如何获得2.7版的Facebook共享计数和评论计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆