parroty / extwitter

Twitter client library for elixir.
MIT License
409 stars 129 forks source link

Jason.DecodeError occurs for deleted Tweets #130

Closed PJUllrich closed 3 years ago

PJUllrich commented 4 years ago

When I run the example code from the docs, I receive Jason.DecodeError whenever a deleted tweet is received. I tried both Jason and Poison and with both libraries, I receive this error. This error causes the stream to stop unfortunately, so the stream_sample/0 function is not usable anymore because of this.

I run this code for example:

stream = ExTwitter.stream_sample(receive_messages: true)
for message <- stream do
  case message do
    tweet = %ExTwitter.Model.Tweet{} ->
      IO.puts "tweet = #{tweet.text}"

    deleted_tweet = %ExTwitter.Model.DeletedTweet{} ->
      IO.puts "deleted tweet = #{deleted_tweet.status[:id]}"

    limit = %ExTwitter.Model.Limit{} ->
      IO.puts "limit = #{limit.track}"

    stall_warning = %ExTwitter.Model.StallWarning{} ->
      IO.puts "stall warning = #{stall_warning.code}"

    _ ->
      IO.inspect message
  end
end

And receive this error for example:

Error returned, stopping stream ({%Jason.DecodeError{data: "{\"delete\":{\"status\":{\"id\":394902689026285568,\"id_str\":\"394902689026285568\",\"user_id\":443203247,\"user_id_str\":\"443203247\"},\"timestamp_ms\":\"1602000249144\"}}\r\n{\"delete\":{\"status\":{\"id\":809866251732389889,\"id_str\":\"809866251732389889\",\"user_id\":2881830944,\"user_id_str\":\"2881830944\"},\"timestamp_ms\":\"1602000248333\"}}\r\n{\"delete\":{\"status\":{\"id\":887357414873468928,\"id_str\":\"887357414873468928\",\"user_id\":1489121804,\"user_id_str\":\"1489121804\"},\"timestamp_ms\":\"1602000248345\"}}\r\n", position: 156, token: nil}, "{\"delete\":{\"status\":{\"id\":394902689026285568,\"id_str\":\"394902689026285568\",\"user_id\":443203247,\"user_id_str\":\"443203247\"},\"timestamp_ms\":\"1602000249144\"}}\r\n{\"delete\":{\"status\":{\"id\":809866251732389889,\"id_str\":\"809866251732389889\",\"user_id\":2881830944,\"user_id_str\":\"2881830944\"},\"timestamp_ms\":\"1602000248333\"}}\r\n{\"delete\":{\"status\":{\"id\":887357414873468928,\"id_str\":\"887357414873468928\",\"user_id\":1489121804,\"user_id_str\":\"1489121804\"},\"timestamp_ms\":\"1602000248345\"}}\r\n"}).

It seems that the incoming data is not separated properly.

PJUllrich commented 4 years ago

This seems to be related to: https://github.com/parroty/extwitter/pull/104

PJUllrich commented 4 years ago

I forked this repo, added the fix from #104 and successfully tested the example code above again. So, this issue will be fixed by #104

mdlkxzmcp commented 3 years ago

This can be closed finally since the aforementioned PR has been merged :>

PJUllrich commented 3 years ago

πŸ’™β€οΈπŸ’›πŸ§‘πŸ’š