jublo / codebird-php

Easy access to the Twitter REST API, Direct Messages API, Account Activity API, TON (Object Nest) API and Twitter Ads API — all from one PHP library.
https://www.jublo.net/projects/codebird/php
GNU General Public License v3.0
777 stars 235 forks source link

Request error for API call: Failed to connect to api.twitter.com port 443: Connection refused #209

Closed ugurkilci closed 5 years ago

ugurkilci commented 7 years ago

Please help me?

Fatal error: Uncaught exception 'Exception' with message 'Request error for API call: Failed to connect to api.twitter.com port 443: Connection refused' in /home/u00000000/public_html/h/src/codebird.php:2098 Stack trace: #0 /home/u00000000/public_html/h/src/codebird.php(2050): Codebird\Codebird->_callApiCurl('GET', 'search/tweets', 'search/tweets', Array, false, false) #1 /home/u00000000/public_html/h/src/codebird.php(846): Codebird\Codebird->_callApi('GET', 'search/tweets', 'search/tweets', Array, false, false) #2 /home/u00000000/public_html/h/index.php(16): Codebird\Codebird->__call('search_tweets', Array) #3 /home/u00000000/public_html/h/index.php(16): Codebird\Codebird->search_tweets(Array) #4 {main} thrown in /home/u00000000/public_html/h/src/codebird.php on line 2098

mmubasher commented 7 years ago

The error Failed to connect to api.twitter.com port 443: Connection refused usually means that the server can't connect to api.twitter.com. Possible reasons could be a firewall or your IP being blocked by Twitter. Have you tried using a Proxy? $foo->setProxy('123.123.123.123', '1234', 'CURLPROXY_HTTP');

Lassitek commented 6 years ago

@ugurkilci I'm getting the same issue. Did you get it to work?

prafullwizorbit commented 6 years ago

I am getting same type of issue and it produced blank page when i use streaming api

Lassitek commented 6 years ago

Ok, apparently it has to do with Twitter randomly blacklisting IP addresses/networks now (like mmubasher said). Whatever your webhost is may be blacklisted and Twitter is making it difficult to cooperate with them. If it is not this or any of the suggestions above, make sure you are connecting to their api's with TLS https://dev.twitter.com/overview/api/tls

eQX8HNMTU2 commented 6 years ago

@cjl014 I am using 000webhost as hosting provider and I am getting this error

how do i fix this issue now

Lassitek commented 6 years ago

@AndiHamolli I'm assuming you're using shared web hosting and/or Free, meaning most likely others are on the same IP address as you. Twitter is blocking 000webhost shared hosting IPs because I use hosting24 which is under HOSTINGER which runs both 000webhost and hosting24, and their support team has informed me of this . 1). So what might work is, you'll have to request for a 'dedicated' IP address, meaning you aren't sharing an IP that will get blacklisted by other spammers using it. Most likely the only way to get a dedicated IP address from them is by upgrading to a VPS (virtial private server), so you'll have your own personal IP. They offer this on hosting24, but the downside is the cost & configuring the server yourself possibly, no regular server maintenance, cost for Cpanel license, but you can use a free alternative cpanel.....(Sentora is not bad) 2.) Use a cloud server (basically the same as VPS just to keep it short). I use Host1Plus for 1 site which is cheaper. 3.) Switch to another host where Twitter isn't blocking their shared webhosting like maybeee GoDaddy, hostGator, or something else that's free instead. You should ask the Support Team on the other sites to see if Twitter's api is blocking their IP addresses. They should want to help a new customer.

If you need help, I will offer my services.

In case anyone thinks that requesting switching IP's on "shared" hosting will work with these guys(000webhost/hosting24), here is a link to answer this to show it won't work: https://www.hosting24.com/faq.php?ID=172

joshuaatkins commented 6 years ago

I can understand you guys going down the route of shared hosting being the cause. Although, unless there are other users of the shared hosting service 'abusing' twitter - I doubt it.

Our server (using a dedicated IP) has made 30 million requests to api.twitter.com in the past 5 days (for codebird-js) and we have never had blacklisting issues.

One thing I would suggest, if you are using the service for volume, is to cache your results especially for data reads.

joshuaatkins commented 6 years ago

The more likely case, is that your provider's firewall eventually blocks destination hosts over x number of concurrent connections.

Lassitek commented 6 years ago

@joshuaatkins You're using a personal server? Or what web host are you using?

Here is one of Hosting24's System Admin department responses to my email: "We are in contact with Twitter, but we do not have good news, it seems part of our network is blacklisted and they are uncooperative in resolving this issue :( We will keep trying to get our IPs working with Twitter, but I cannot promise anything judging from their response :(" -End quote

First time using the Twitter's Api under hosting24. And 000webhost is usually for free users where many do abuse it, plus those 2 hosts are under the same company and 000webhost used to send their users to hosting24(which is why I'm using it). They changed up their style the past few years. In my case, the system administrators of those webhosting companies gave me that extra info confirming it's Twitters API blocking them, so I doubt it. And I assume that's AndiHamolli's case too, but everyone else is on their own. Your dedicated IP should be good since you're not spamming and using security most likely, which is why I suggested VPS because that's the only way if they want to stay under the 000webhost (HOSTINGER) company. It's not versatile like GoDaddy. My local server can access Twitter's API with no problem (testing purposes), but this specific website is under hosting24. Usually more trustworthy shared hosting like godaddy and hostgator.. Twitter will cooperate with their companies better than a company like hosting24 who has a reputation. I have used all 4 webhosting sites that I listed so I have experience with their tech teams too. Plus, I already had IP blacklisting issues in the past when using hosting24 which is why with certain websites.. I moved to a cloud server with it's own IP and never have those issues again. Also, I never truly said shared-hosting was the true cause because in point #3 I suggested goDaddy and Hostgator.

This will probably be my last long response because I have things to work on. But I gave as much info as my time allowed me to and shared as much of my experiences that I had over the years. -Hope

mynetx commented 5 years ago

@cjl014 @ugurkilci I fear there is not much that we can do if your server is blacklisted and blocked from accessing the Twitter API.