How to get public wall posts with the facebook API

前端 未结 2 1765
甜味超标
甜味超标 2020-12-24 09:09

I m trying to get wall posts from a profile facebook. I have no problems with the fan pages and my user token is valid (at least for the fan pages).

Example with thi

2条回答
  •  Happy的楠姐
    2020-12-24 09:42

    I dont know if this post is too old, but i just found it while I was searching for a solution to my problem.

    Anyway, I'll just show how I managed to get feeds from a public user:

            var fbul = "https://graph.facebook.com/oauth/access_token?type=client_cred&client_id=[AppID]&client_secret=[AppSecret]";
            var fburl = "https://graph.facebook.com/201317759900688?fields=feed&";
    
            $.get(fbul, function(auth_token){
                $.ajax({
                    dataType: "jsonp",
                    url: fburl+auth_token,
                    success: function(res){
                        console.log(res);
    
                    }
                });
            });
    

    And here a litte explanation: you have to go to the facebook dev console (https://developers.facebook.com) and register a new web App. Just go on "My Apps" in the top Nav and go on "Add a new App". Once thats done you can access your App ID and your APP Secret.

    The first link "var fbul" is to get your access_token which you need to access the feeds.

    var fbul = "https://graph.facebook.com/oauth/access_token?type=client_cred&client_id=[AppID]&client_secret=[AppSecret]";
    

    Just change [AppID] and [AppSecret] to your own keys.

    The second link is to access the feed(we dont add the acces_token here because we do that in our ajax request)

    var fburl = "https://graph.facebook.com/201317759900688?fields=feed&";
    

    The number here(2013177599....) is the channel ID from a public site. To get that number just go on http://findmyfacebookid.com/ and enter the facebook URL to the public user.

    Thats pretty much everything you need.

    Now write your ajax request as followed:

    $.get(fbul, function(auth_token){
                $.ajax({
                    dataType: "jsonp",
                    url: fburl+auth_token,
                    success: function(res){
                        console.log(res);
    
                    }
                });
            });
    

    You'll see now the results in your console.

    Use the success function to handle the results the way you want.

提交回复
热议问题