Is anyone else having a difficult time getting Twitters oAuth\'s callback URL to hit their localhost development environment. Apparently it has been disabled recently. http:
It can be done very conveniently with Fiddler:
127.0.0.1 your-production-domain.com
, make sure that "Enable remapping of requests..." is checked. Don't forget to press Save.A pleasant bonus is that you can specify a custom port, like this:
127.0.0.1:3000 your-production-domain.com
(it would be impossible to achieve this via the hosts file). Also, instead of IP you can use any domain name (e.g., localhost
).
This way, it is possible (but not necessary) to register your Twitter app only once (provided that you don't mind using the same keys for local development and production).
edit this function on TwitterAPIExchange.php at line #180
public function performRequest($return = true)
{
if (!is_bool($return))
{
throw new Exception('performRequest parameter must be true or false');
}
$header = array($this->buildAuthorizationHeader($this->oauth), 'Expect:');
$getfield = $this->getGetfield();
$postfields = $this->getPostfields();
$options = array(
CURLOPT_HTTPHEADER => $header,
CURLOPT_HEADER => false,
CURLOPT_URL => $this->url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false
);
if (!is_null($postfields))
{
$options[CURLOPT_POSTFIELDS] = $postfields;
}
else
{
if ($getfield !== '')
{
$options[CURLOPT_URL] .= $getfield;
}
}
$feed = curl_init();
curl_setopt_array($feed, $options);
$json = curl_exec($feed);
curl_close($feed);
if ($return) { return $json; }
}
Looks like Twitter now allows localhost
alongside whatever you have in the Callback URL
settings, so long as there is a value there.
I struggled with this and followed a dozen solutions, in the end all I had to do to work with any ssl apis on local host was:
Go download: cacert.pem file
In php.ini
* un-comment and change:
curl.cainfo = "c:/wamp/bin/php/php5.5.12/cacert.pem"
php.ini
file is on your machine by running php --ini
in your CLII had the same challenge and I was not able to give localhost as a valid callback URL. So I created a simple domain to help us developers out: https://tolocalhost.com
It will redirect any path to your localhost domain and port you need. Hope it can be of use to other developers.
Alternative 1.
Set up your .hosts (Windows) or etc/hosts file to point a live domain to your localhost IP. such as:
127.0.0.1 xyz.com
where xyz.com is your real domain.
Alternative 2.
Also, the article gives the tip to alternatively use a URL shortener service. Shorten your local URL and provide the result as callback.
Alternative 3.
Furthermore, it seems that it works to provide for example http://127.0.0.1:8080
as callback to Twitter, instead of http://localhost:8080
.