如何让Twitter PHP类在IIS8上工作(卷曲问题?)

I decided to combine my website with my twitter account. In order to use it properly, I wanted to post a tweet. I decided to go with the very simple class TwitterAPIExchange from here: https://github.com/J7mbo/twitter-api-php

I tested it on my Linux server and it all works well. But I wanted to use this tool from my Windows server. This is my set up: Windows 2012, IIS 8, PHP.

Here my test code

// Setup
$settings = array( ... );
$url = 'https://api.twitter.com/1.1/statuses/update.json';

// Post the data
$requestMethod = 'POST';

$postfields = array('status' => 'Hello World');

$twitter = new TwitterAPIExchange($settings);
$json = $twitter->buildOauth($url, $requestMethod)->setPostfields($postfields)->performRequest();

var_dump($json);

On the windows machine, it returns

bool(false)

all the time! What does that mean? Is it an issue with curl and IIS? I read several articles online about it but none helped me so far. Any input is very appreciated!

Curl gave me the following error:

curl iis SSL certificate problem, verify that the CA cert is OK

As I could not make it work with a certificate on IIS, I folllowed a hint given on a forum (http://board.phpbuilder.com/showthread.php?10253357-cURL-and-SSL-issues) which told me to add the following curl options:

curl_setopt( $ch , CURLOPT_SSL_VERIFYPEER , false );
curl_setopt( $ch , CURLOPT_SSL_VERIFYHOST , false ); 

So in the end, I added this to the TwitterAPIExchange class where curl was used.

You likely have to download a certificate package and point the script to it. The following should work:

  1. Save this file to the same directory as the PHP files: http://curl.haxx.se/ca/cacert.pem
  2. Add CURLOPT_CAINFO => 'cacert.pem' to the options section, which starts at line 192 of the current version of the code: https://github.com/J7mbo/twitter-api-php/blob/master/TwitterAPIExchange.php#L192

You could also use another valid certificate bundle and save it elsewhere, so long as you include the path to it in the code.