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
960 stars 303 forks source link

Callback function doesn't fire when including Twitter #194

Open ricardo-lewis opened 8 years ago

ricardo-lewis commented 8 years ago

I can access Instagram and Facebook and the callback function will execute. But when I add Twitter, or even just access Twitter by itself, the callback function never runs.

HartLarsson commented 8 years ago

if callback is not firing could be a problem that twitter not collect nothing and/or nr. of post collected are < of max post you specify. I've put a fix in my version, a fix not made by me but i've applied and works great. Feel free to to use my forked version to test

ricardo-lewis commented 8 years ago

Less than the max number of posts makes sense, thanks. I'll have a look at your fix.

ricardo-lewis commented 8 years ago

@HartLarsson I tried using your version but the callback function still doesn't fire unless I remove Twitter. It shouldn't be a big deal, I think it's only because the Twitter account only has 3 posts in it :-)

HartLarsson commented 8 years ago

can you provide me your sample page so i can debug?

ricardo-lewis commented 8 years ago

Not really, I'm developing locally. I'm think the problem will go away once I have more than 3 tweets on that account.

HartLarsson commented 8 years ago

no, even with one tweet only, it works. so the problem is not on the js.

ricardo-lewis commented 8 years ago

Here is the JS that powers the social feed (names have been changed to protect the innocent):

$('.social-feed-container').socialfeed({
        'twitter':{
            accounts: ['@atmwebdev'],
            limit: 4,
            consumer_key: 'ABCDEF',
            consumer_secret: 'ABCDEF'

        },  
      'instagram':{
          accounts: ['@this_user_works_fine'],  
          limit: 4,
           client_id: 'ABCDEF',      
            access_token: 'ABCDEF'
      },
        'facebook':{
            accounts: ['@atmwebdev'],
            limit: 4,
            access_token:'ABCDEF'
        },
      // GENERAL SETTINGS
      length:100,
      template: window.social_feed_template,
      show_media: true,
      callback: function() {                         
            log("All posts collected!");
        }
  });

And as I've already mentioned, the final callback function only triggers when I comment out the Twitter section entirely.

This is the HTML, which seems to work fine regardless:

<div class="social-feed"><div class="row"><div class="column"><ul class="medium-block-grid-3 large-block-grid-4 social-feed-container"></ul></div></div></div>

The social feed template uses LI tags to enclose each post.

ricardo-lewis commented 8 years ago

@HartLarsson when I set the Twitter limit parameter to less than the amount of tweets available in the timeline, the callback function executes. There are only 3 tweets on my timeline, when I set the limit to 2, it all works fine.

HartLarsson commented 8 years ago

this thing have no sense really, looking the piece of code that calculate the ammount of feed to load:

 utility: {
                    getPosts: function(json) {
                        if (json) {
                            // fix callback
                            console.log(json.length);
                            if(json.length < options.twitter.limit)
                                posts_to_load_count -= options.twitter.limit - json.length;
                            $.each(json, function() {
                                var element = this;
                                var post = new SocialFeedPost('twitter', Feed.twitter.utility.unifyPostData(element));
                                post.pushData();
                            });
                        }
                    },

must work! I've added a console.log(json.length); to see in the log how many post it collect. Please add the modification and see how many are returned.

ricardo-lewis commented 8 years ago

I added the line:

console.log(json.length);

And it returns the correct number, which is the limit option for Twitter (above).

If I set the Twitter limit to a number (e.g. 20) higher than the actual number of tweets in the timeline (currently 7) then the callback never executes.

Which is fine, I'm sure the author never imagined a scenario like this.

HartLarsson commented 8 years ago

is strange must return 7, the length of the feed recovered by twitter and not 0 (the limit you put). I've tested in my version and it works as intended for me. Probably there is an error to check in the json return. Yuo can provide me in private mode the twitter parameters you use so i can debug with a empty twitter like yours?

ricardo-lewis commented 8 years ago

Honestly I just made a twitter account specifically for testing. It's free and apparently it's the correct thing to do since Twitter doesn't have a sandbox mode. Just try that, then you have a Twitter timeline with nothing in it.

nicosuria commented 8 years ago

There's a PR addressing this: https://github.com/pavelk2/social-feed/pull/173