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
963 stars 304 forks source link

frequently 400 server rss responde #277

Open kampiamodikuesto opened 6 years ago

kampiamodikuesto commented 6 years ago

the script sometime works and sometime not, i have to reload many times the page to get some rss. This is my configuration:

...
$('#carousel-social-feed-inner').socialfeed({
                /*
                // FACEBOOK
                facebook:{
                    accounts: ['@teslamotors','!teslamotors'],  //Array: Specify a list of accounts from which to pull wall posts
                    limit: 2,                                   //Integer: max number of posts to load
                    access_token: 'YOUR_FACEBOOK_ACCESS_TOKEN'  //String: "APP_ID|APP_SECRET"
                },            

                // TWITTER
                twitter:{
                    accounts: ['@Sportware_org'],                      //Array: Specify a list of accounts from which to pull tweets
                    limit: 4,                                   //Integer: max number of tweets to load
                    consumer_key: 'YOUR_CONSUMER_KEY',          //String: consumer key. make sure to have your app read-only
                    consumer_secret: 'YOUR_CONSUMER_SECRET_KEY' //String: consumer secret key. make sure to have your app read-only
                },          
                */
                // RSS
                rss:{
                    urls: ['http://www.ansa.it/sito/ansait_rss.xml'], //Array: Specifiy a list of rss feed from which to pull posts
                    limit: 4                                      //Integer: max number of posts to load for each url
                },          

                // GENERAL SETTINGS
                length:400,
                show_media:true,
                media_min_width: 300, 
                template: "bower_components/template.html",                                      //Integer: For posts with text longer than this length, show an ellipsis.
                template_html: 
                    '<div class="item"><h4>{{=it.author_name}}</h4><p>{{=it.text}} \
                    <i class="fa \
                    {{? it.social_network == "twitter"}} fa-twitter {{?}} \
                    {{? it.social_network == "facebook"}} fa-facebook {{?}} \
                    {{? it.social_network == "rss"}} fa-flickr {{?}}" \
                    aria-hidden="true"></i></p></div></div>',
...

when nothing is displayed/grapped form social, on the console i get an object with

why the rss server responde with 400? i try with different rss url but i get same behaver (sometime load rss some time no)

200 Server Response

400 Server Response

HartLarsson commented 6 years ago

seems that yahoo rss feed api have sometimes some problem to get the feed and output the json. We need to switch to another service like https://rss2json.com

HartLarsson commented 6 years ago

please don't use at the same time:

template: "bower_components/template.html",
and template_html: '....'

kampiamodikuesto commented 6 years ago

thanks for replay, i have to use rss2json.com services instead to insert direct feed url?

HartLarsson commented 6 years ago

no, is an alternative o yahoo and must be implemented inside the social-feed core script.

kampiamodikuesto commented 6 years ago

i woul like to use your script to use with flicker rss. i have to edit your script and add a module to use rss2json output?

HartLarsson commented 6 years ago

change RSS processor means rewrite completely the core script based on the new API. Is something that keep lot of time and need lot of testing

mistafi commented 5 years ago

@HartLarsson Have there been any moves on this? I've been working on replacing yahoo with rss2json. So far so good, but I'm getting:

Uncaught TypeError: Cannot read property 'feed' of undefined

on this line:

$.each(json.responseData.feed.entries, function(index, element)

Even though the feeds are logging out properly in the console.

So far, I've been able to add the api key in the insert file and make a few changes to socialfeed.js:

`
rss : { posts: [], loaded: false, api : 'https://api.rss2json.com/v1/api.json',

            getData: function(url) {
              var count = options.rss.limit,
              limit = '&count='+ count,
              key = '&api_key=' + options.rss.key,
              url = '?rss_url=' + encodeURIComponent(url),
              request_url = Feed.rss.api + url + key + limit + '&format=json&callback=?';

              Utility.request(request_url, Feed.rss.utility.getPosts, Feed.rss.datatype);
            },

            utility: {

             getPosts: function(json) {
             console.log(json);
                    $.each(json.responseData.feed.entries, function(index, element) {  
                        var post = new SocialFeedPost('rss', Feed.rss.utility.unifyPostData(index, element));
                        post.render();
                    });
                }, 
                unifyPostData: function(index, element){
                    var post = {};

                    post.id = index;
                    post.dt_create= moment(element.publishedDate, 'ddd, DD MMM YYYY HH:mm:ss ZZ', 'en');
                    post.author_link = '';
                    post.author_picture = '';
                    post.author_name = element.author;
                    post.message = Utility.stripHTML(element.title);
                    post.description = Utility.stripHTML(element.content);
                    post.social_network = 'rss';
                    post.link = element.link;
                    if (options.show_media && element.mediaGroups ) {
                        post.attachment = '<img class="attachment" src="' + element.mediaGroups[0].contents[0].url + '" />';
                    }
                    return post;
                }
            }
        }

`

I am obviously missing something, but I am having trouble figuring out what it is.

I appreciate any help you can lend.

Thanks!

Also:

I have tried using:

getPosts: function(json) { console.log(json); if (json.query.count > 0 ){ $.each(json.query.results.feed, function(index, element) { var post = new SocialFeedPost('rss', Feed.rss.utility.unifyPostData(index, element)); post.render(); }); } },

and I get this error:

Uncaught TypeError: Cannot read property 'count' of undefined

at this line:

if (json.query.count > 0 ){

HartLarsson commented 5 years ago

Very strange, the syntax is correct but you can try only with:

if (json.query.count) { // your code here }

mistafi commented 5 years ago

Thank you for your reply!

I have made a few adjustments:

` rss : { posts: [], loaded: false, api : 'https://api.rss2json.com/v1/api.json',

            getData: function(url) {
              var counter = options.rss.limit,
              limit = '&count='+ counter,
              key = '&api_key=' + options.rss.key,
              rssurl = '?rss_url=' + encodeURIComponent(url),
              request_url = Feed.rss.api + rssurl + key + limit + '&format=json&callback=?';

                Utility.request(request_url, Feed.rss.utility.getPosts);
            },
            utility: {

                getPosts: function (json) {
                console.log(json.status);
                console.log(json.feed.title);
                console.log(json.items.length);
                console.log(json.feed);
                console.log(json.query.count);

                    if(json.status == 'ok') {
                        $.each(json.items, function(index, element) {
                            var element = this;
                            var post = new SocialFeedPost('rss', Feed.rss.utility.unifyPostData(index, element));
                            post.render();
                        });
                    }
                },

                unifyPostData: function(index, element){
                    var post = {};

                    post.id = index;
                    post.dt_create= moment(element.publishedDate, 'ddd, DD MMM YYYY HH:mm:ss ZZ', 'en');
                    post.author_link = '';
                    post.author_picture = '';
                    post.author_name = element.author;
                    post.message = Utility.stripHTML(element.title);
                    post.description = Utility.stripHTML(element.content);
                    post.social_network = 'rss';
                    post.link = element.link;
                    if (options.show_media && element.mediaGroups ) {
                        post.attachment = '<img class="attachment" src="' + element.mediaGroups[0].contents[0].url + '" />';
                    }
                    return post;                    }                
             }
        }
    };

`

This kinda works, but not really.

console.log(json.status); console.log(json.feed.title); console.log(json.items.length); console.log(json.feed); console.log(json.query.count);

json.status = ok json.feed.title = my feed titles, all three of them json.items.length = 2 (picking this up from the insert.js) json.feed = displays feed info json.query.count = Uncaught TypeError: Cannot read property 'count' of undefined

It also is rotating between the three RSS feeds and showing only the 2 posts from one at load time.

Additionally, it simply says "Invalid Date" in the top right corner of the loaded posts.

Aside from this, the Twitter feed is loading and displaying properly.

I appreciate your help!