0

I am working mvc application i have tried to get facebook share count.

Can i get face book share count using only facebook AppId my code below Or (Could you please check my call back function which is working i got response as alert but there is in ajax method could not rendering it. is there any wrong please help me)

 <img src="~/images/icons/fb.png" style="cursor: pointer; margin-left:
5px;" title="Facebook" onclick="sendRequest()" />
<script>
    FB.https = true;
    FB.init({
        appId: '********',
        cookie: true,
        status: true,
        xfbml: true
    });

    function sendRequest() {

        var obj = {
            method: 'feed',
            link: 'https://www.oppd.org/p/' + '@Model.ProductId',
            caption: '@Model.Message',
        };

        function callback(response) {
            alert("Post ID: " + response['post_id']);
            var PostId=response['post_id'];                
             var _url = '@Url.Action("Social")';
            $.ajax({
                url: _url,
                type: "GET",
                dataType: 'json',
                success: function (data) {

                }
            });
                        }
        FB.ui(obj, callback);
    }
mhlester
  • 22,781
  • 10
  • 52
  • 75
Sajith
  • 856
  • 4
  • 19
  • 48
  • I not sure about `mvc` but you can check out my answer here http://stackoverflow.com/a/21016937/2151050 – Adam Azad Jan 24 '14 at 07:05

1 Answers1

1

Here is the code to get share count from facebook using AppId. It may help you.

<script src='https://connect.facebook.net/en_US/all.js'></script>

<script> 
var apid = "Your AppId";
FB.init({appId: apid, status: true, cookie: true});

function sendRequest(){
    FB.login(function(response) {
        if (response.authResponse){                                                                         
            FB.api({
                method: 'fql.query',
                query: 'SELECT share_count FROM link_stat WHERE url = "....Your link..."'
            }, function(res){
                alert('Share count = '+res[0].share_count);         
            });
        } else {
            console.log('User cancelled login or did not fully authorize.');
        }
    },{
        scope:'read_stream,publish_stream,offline_access'
    }); 
}

</script>
<input type="button" value="Get Share" onclick="sendRequest();" />
Blundering Philosopher
  • 6,245
  • 2
  • 43
  • 59
Prabhudas
  • 82
  • 1
  • 5