How do I get a Twitter feed using Pharo?
Asked Answered
E

2

5

Since Twitter changed their website design, I cannot get a set of tweets from any account by using built-in Zinc classes. It throws an error that says: ConnectionClosed: Connection closed while waiting for data

I am using Pharo 5, and I don't know how to tweak the ZnClient settings in order to keep the connection open or something to the purpose of getting the data.

testTwitter
    | client |
    self ensureSocketStreamFactory.
    self isNativeSSLPluginPresent ifFalse: [ ^ self ]. 
    (client := ZnClient new) 
        get: 'https://www.twitter.com/pharoproject'.
    self assert: client isSuccess.
    self assert: (client contents includesSubstring: 'Twitter').
    client close

That's the test I have in place, it never passes, and throws the error mentioned above. What's missing here? I did a Ruby script using open-uri, openssl and Nokogiri and it fetched the tweets just fine. Perhaps it's a problem with the SSL connection itself?

Euphonious answered 6/8, 2019 at 12:36 Comment(0)
Y
4

The issue here is quite easy to answer, but you won't like it. Your issue is connected to the fact that the Twitter has deprecated support for TLS 1.0, TLS 1.1 on July 15/2019. Your pharo is using the deprecated TLS to connect. That is the reason why you are getting the timeout.

The solution?

You have to compile the new SSL/TLS support yourself which is not an easy task to do. You have to compile in at least TLS 1.2 to be able to connect again. There is lack of Pharo documentation how to compile support for new libraries. My guess is that you are using TLS 1.0 (see a note below) - since Pharo 6.1 (so your Pharo 5.x will have same or older libraries) has libgit2.so compiled against libssl.so.1.0.0 (which has dependency libcurl-gnutls.so.4) - If you update the libraries you can see that those support >= TLS 1.2.

Note:

This is connected to the issue which I have posted some time ago. Nobody upvoted it or answered so it got automatically deleted - you can vote to undelete it: https://mcmap.net/q/2036180/-getting-error-when-adding-ossubprocess-to-my-pharo-6-1-on-centos-7-4x (see the bottom of the post for the question). I don't have an answer for that as I have dedicated time to my Smalltalk/X project.

Yasmineyasu answered 13/8, 2019 at 8:31 Comment(0)
B
2

Or just switch to a newer Pharo. Adding your method to ZnHTTPSTest in Pharo 8 just works (tested on Pharo 8 build 686, Ubuntu 18.04.02 LTS with the stable vm in PharoLauncher)

Bestraddle answered 2/9, 2019 at 15:7 Comment(1)
That is true, but the question is why you would have to change Pharo version when you have your code working and deployed. It would be much easier to have a documented way to recompile new libraries against any Pharo version.Yasmineyasu

© 2022 - 2024 — McMap. All rights reserved.