pavelk2 / social-feed

JavaScript plugin that shows a user feed from the most popular social networks
http://pavelk2.github.io/social-feed-example/
MIT License
962 stars 304 forks source link

TypeError: element.from is undefined #118

Closed ilomedia closed 9 years ago

ilomedia commented 9 years ago

Hi all,

I'm trying to install your plugin on a test site, my code follows. The only difference between your demo and my code is that i created a new FB App and gor an App ID and i get the following error : TypeError: element.from is undefined on line 266 post.author_link = 'http://facebook.com/' + element.from.id;

element is the post from teslamotors which works fine in your example, am i stupid or is there something wrong?

$(document).ready(function(){
            $('.accAPicture').socialfeed({
                // FACEBOOK
                facebook:{
                    accounts: ['@teslamotors','!teslamotors'],
                    limit: 2,
                    access_token: '1134255683255293|eSI1YYsy6iajeWZ7N94SSP9on_Q' // APP_ID|APP_SECRET
                },
                // GENERAL SETTINGS
                length:400,
                show_media:true,
                // Moderation function - if returns false, template will have class hidden
                moderation: function(content){
                    return  (content.text) ? content.text.indexOf('fuck') == -1 : true;
                },
                //update_period: 5000,
                // When all the posts are collected and displayed - this function is evoked
                callback: function(){
                    console.log('all posts are collected');
                },
                template:'/typo3conf/ext/smeno/Resources/Public/Js/SocialFeed.html'
            });
        });
etienne-martin commented 9 years ago

I had the same issue.

That's because your faceook app is running a newer version of the graph API. If I get it right, we need to specify which fields we want to retrieve since version 2.4.

Simply replace the line 303 in jquery.socialfeed.js with the following:

request_url = Feed.facebook.graph + 'v2.3/' + page + '/feed?fields=id,from,name,message,created_time,story,description,link,picture,object_id&' + limit + query_extention;
etienne-martin commented 9 years ago

Also, replace the line 296 with the following:

request_url = Feed.facebook.graph + 'v2.3/' + userdata.id + '/posts?fields=id,from,name,message,created_time,story,description,link,picture,object_id&' + limit + query_extention;
ilomedia commented 9 years ago

Indeed my app runs API Version 2.4

Thanks for the workaround but i think a definitive solution should be handled by the official plugin. Maybe you could propose a patch?

Or maybe API Version is already handled as an option, i'll check

etienne-martin commented 9 years ago

The API version value is hard coded, it's not handled as an option.