Twitter的API上的XAMPP返回NULL [英] Twitter API returns NULL on XAMPP
问题描述
我试图让到Twitter API的调用。
在短期我的问题是描述这里相同。使我的电话,我得到 NULL
在的var_dump()
的结果。
然而
卷曲工作得很好,我已经包括了最新版本的的 Twitter的API的PHP 的脚本,所有的令牌,密钥和秘密是正确的。
我工作的地方XAMPP安装。这是否会导致问题?但它似乎替别人打工。 PHP是配置错误在我的情况?还是我只是想念一个分号(我怀疑,因为我没有得到任何错误)?
这是我的code:
的ini_set('display_errors设置',真);
require_once('\\库\\ TwitterAPIExchange.php');$设置=阵列(
oauth_access_token'=> ############,
oauth_access_token_secret'=> ############,
CONSUMER_KEY'=> '########',
CONSUMER_SECRET'=> ###########
);$ URL ='https://api.twitter.com/1.1/statuses/user_timeline.json';$ requestMethod =GET;'?SCREEN_NAME = J7mbo'$ = getfield命令;$叽叽喳喳=新TwitterAPIExchange($设置);
$响应= $ twitter-> setGetfield($ getfield命令)
- > buildOauth($网址,$ requestMethod)
- > performRequest();后续代码var_dump(json_de code($响应));
神保一样在上面的评论中指出,该解决方案可以发现<一个href=\"http://snippets.webaware.com.au/howto/stop-turning-off-curlopt_ssl_verifypeer-and-fix-your-php-config/\">here
根据这篇文章,在Windows PHP发行不来与CA根证书的最高最新的包。
然而,包可以在这里下载 。我把它放在 C:\\ XAMPP \\ PHP \\ cacert.pem
第二步是添加 curl.cainfo = C:\\ XAMPP \\ PHP \\ cacert.pem
在php.ini文件的末尾。
路径更改为您的文件夹下保存的.pem文件。
重新启动Apache和现在的问题应该得到解决!
谢谢!
I'm trying to make a call to the Twitter API.
In short my problem is the same one as described here. Making my call I get NULL
on a var_dump()
of the result.
However
cURL works fine, I have included the newest version of the twitter-api-php script and all the tokens, keys and secrets are correct.
I'm working on a local XAMPP installation. Does this cause the problem? But it seems to work for other people. Is php configured wrong in my case? Or did I simply miss a semicolon (which I doubt because I don't get any errors)?
Here is my code:
ini_set('display_errors', true);
require_once('.\libs\TwitterAPIExchange.php');
$settings = array(
'oauth_access_token' => '############',
'oauth_access_token_secret' => '############',
'consumer_key' => '########',
'consumer_secret' => '###########'
);
$url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
$requestMethod = "GET";
$getfield = '?screen_name=J7mbo';
$twitter = new TwitterAPIExchange($settings);
$response = $twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest();
var_dump(json_decode($response));
Like Jimbo pointed out in the comments above, the solution can be found here
According to the article, the Windows PHP distribution doesn't come with an up-to-date bundle of the CA root certificates.
However, the bundle can be downloaded here. I put it under C:\xampp\php\cacert.pem
.
The second step is to add curl.cainfo=c:\xampp\php\cacert.pem
at the end of your php.ini file.
Change the path to your folder where you saved the .pem-file.
Restart Apache and now the problem should be solved!
Thanks!
这篇关于Twitter的API上的XAMPP返回NULL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!