简体   繁体   中英

Facebook Graph API to Pull News Feed. Replace discontinued RSS/XML

OK, Since facebook has discontinued their RSS feed for their news feed. I've been trying to figure out how to use Graph API to pull the newsfeed in. I've been searching but i can not find anything. Am I doing this right? Tried going through the developer.fb docs but can't seem to get it right. What am I doing wrong? This is what I've done: I created an App in developer.fb. enabled user_feed, read_stream (yes i know it is being deprecated), and user_status. I've also enabled it or made it live. All i want to do is put the news feed on another website.

My code is as followed (tried two methods):

` Open Graph rss

</head>
<body>
    <script>
        window.fbAsyncInit = function() {
            FB.init({
                appId      : 'MyAppID',
                xfbml      : true,
                version    : 'v2.4'
            });
        };

        (function(d, s, id){
            var js, fjs = d.getElementsByTagName(s)[0];
            if (d.getElementById(id)) {return;}
            js = d.createElement(s); js.id = id;
            js.src = "//connect.facebook.net/en_US/sdk.js";
            fjs.parentNode.insertBefore(js, fjs);
        }(document, 'script', 'facebook-jssdk'));
    </script>

    <script>
        function feed() {
            FB.api(
                "/me/feed",
                function (response) {
                    if (response && !response.error) {
                        document.write('are we here?'); //no
                        document.write(response.data.message);
                    }
                }
            );   
        }



        function feed2(){

            var page_id = 'my_pageID';  //Also tried appid
            var pageaccessToken='MyAppToken';

            FB.api('/' + $page_id + '/feed?access_token=' + pageaccessToken, function(response){
                document.write("am i here?"); // does not get here
                if (response && response.data && response.data.length){
                    var ul = document.getElementById('pagefeed');
                    for (var j=0; j < response.data.length; j++){
                        var feed = response.data[j];
                        document.write(feed.message);
                        document.write(feed.link);
                    }
                }
            });
        }

    </script>


    <button onclick="feed()">test</button> 
    <button onclick="feed2()">feed</button>

</body>

`

Just for your information. You actually CAN view your pages feed and it's very very simple:

https://graph.facebook.com/ {Page-ID}/posts?access_token={access-Token}

You need to create a graph API app to get an access token. but it's possible

check it:

http://johndoesdesign.com/blog/2011/php/adding-a-facebook-news-status-feed-to-a-website/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM