sonnyt / tweetie

Simple jQuery Twitter feed plugin
https://sonnyt.com/tweetie
312 stars 117 forks source link

The only result is a for each error #93

Open retsoced opened 6 years ago

retsoced commented 6 years ago

No matter what the settings, the function only returns an error: TypeError: e.forEach is not a function

I assume this is returning no results, but everything seems to be set correctly. $('.tweetfeed').tweetie({ "url": "/api/", "type": "timeline", "template": "<li>{{tweet.created_at}} - {{tweet.text}}</li>", "dateFormat": "%b %d, %Y", "params": { "count": 15 } });

dgastudio commented 6 years ago

same here

simonleadbetter commented 6 years ago

Yup. I see the same error.

sonnyt commented 6 years ago

That is strange, do you have an endpoint I can try out? Also, which API you guys are using?

simonleadbetter commented 6 years ago

PHP. Unfortunately, I can not share the endpoint on this post due to client confidentiality.

<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
  <script src="/dist/tweetie/dist/tweetie.min.js"></script>

  {# {% do view.registerJsFile("/dist/tweetie/dist/tweetie.min.js") %} #}

  <script type="text/javascript">
    $('#tweets').tweetie({
      url: '/dist/tweetie/api/php/tweetie.php',
      type: 'timeline',
      template: '<li>{% verbatim %}{{tweet.created_at}}{% endverbatim %} - {% verbatim %}{{tweet.text}}{% endverbatim %}</li>',
      dateFormat: '%b %d, %Y',
      params: {
        count: 15,
        screen_name: null,
        exclude_replies: false,
        include_rts: false
      }
    });
</script>

The {% verbatim %} tags are there to stop a clash with Craft CMS.

In case it is useful, I have downloaded the files via bower.

sonnyt commented 6 years ago

@simonleadbetter is your PHP file hosted somewhere on a server? Like can you call that page via postman or browser directly? Just curious if it's returning any response.

simonleadbetter commented 6 years ago

It is, but I can not publish the URL as the site is in development. Is there a way I can share the URL with you so it is not public?

The tweetie.php file is executing on the server.

robwent commented 5 years ago

I'm getting the same thing using the timeline endpoint.

This is the response from twitter: https://gist.github.com/robwent/738cb69ae000619995b4e92d65b6eb86

Browser console error:

   tweetie.min.js:1 Uncaught TypeError: e.forEach is not a function
    at Object.<anonymous> (tweetie.min.js:1)
    at fire (jquery.js?0edfd041b07867c9ed3ac92157993e2a:3232)
    at Object.fireWith [as resolveWith] (jquery.js?0edfd041b07867c9ed3ac92157993e2a:3362)
    at done (jquery.js?0edfd041b07867c9ed3ac92157993e2a:9840)
    at XMLHttpRequest.callback (jquery.js?0edfd041b07867c9ed3ac92157993e2a:10311)

Same thing testing with other endpoints.

The username I'm searching for is also being ignore and the response is for the user that created the twitter app to get the keys.

robwent commented 5 years ago

I fixed my issue with the username. The params were getting lost.

I now get the tweets from the user, but the foreach error is still the same.

New response: https://gist.github.com/robwent/1b460cf4a96cf43e1e34428cb4390057

robwent commented 5 years ago

I've uploaded to a demo site if that's any easier: https://ovrr.to/Lc6Lq The tweets should show next to the news section.

I've tried different versions of jQuery but got the same result with all of them.

robwent commented 5 years ago

There are 2 tweetie.min.js files in the dist folder.

The first one is the one that causes the foreach error.

The secodnd one in dist/dist that gets built by webpack shows:

Uncaught TypeError: Cannot read property 'errors' of undefined
    at Object.<anonymous> (tweetie.min.js:1)
    at i (jquery.min.js?237c0a7d609dc2e7cae6d026920286c2:2)
    at Object.fireWith [as rejectWith] (jquery.min.js?237c0a7d609dc2e7cae6d026920286c2:2)
    at y (jquery.min.js?237c0a7d609dc2e7cae6d026920286c2:4)
    at XMLHttpRequest.c (jquery.min.js?237c0a7d609dc2e7cae6d026920286c2:4)

I got rid of the foreach error using this: https://stackoverflow.com/a/35970005/931438

But then I got other errors related to the month strings.

Makes me wonder if it's the es version bable is compiling to, but for now, I've gone back to 2.4.3 and got that working with the server version from 3.

sonnyt commented 5 years ago

@robwent I just checked out your website, it looks like the index.php?option=com_ajax&module=etsi_twitter&format=raw endpoint is returning using the text/html content type, can you try changing that to application/json?

robwent commented 5 years ago

oh la la, I didn't think about that.

I just got it working with a mixture of the old/new versions, but I'll test that out and let you know.

robwent commented 5 years ago

I still get the same when the response is returned with the header: Content-Type: application/json; charset=utf-8

sonnyt commented 5 years ago

@robwent that is strange, do you have link I can check out?

robwent commented 5 years ago

Not live, but it will return the json header by changing the url to index.php?option=com_ajax&module=etsi_twitter&format=json

So I put the latest js version back and changed the js to use the settings params array and got the same foreach error.

I'll try it out again later as I'd like to use more than the old templating placeholders.

bilalmalkoc commented 5 years ago

Any solution? I have same issue.

BN83 commented 4 years ago

I've got the same issue too. Any update on this?