Twitter API 在 XAMPP 上返回 NULL [英] Twitter API returns NULL on XAMPP
问题描述
我正在尝试调用 Twitter API.
I'm trying to make a call to the Twitter API.
简而言之,我的问题与此处所述相同.拨打我的电话,我在结果的 var_dump()
上得到 NULL
.
In short my problem is the same one as described here. Making my call I get NULL
on a var_dump()
of the result.
不过
cURL 工作正常,我已经包含了 twitter-api-php 脚本的最新版本,并且所有令牌、密钥和秘密都是正确的.
cURL works fine, I have included the newest version of the twitter-api-php script and all the tokens, keys and secrets are correct.
我正在本地安装 XAMPP.这会导致问题吗?但它似乎对其他人有效.在我的情况下,php 配置错误吗?还是我只是漏掉了一个分号(我对此表示怀疑,因为我没有收到任何错误)?
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)?
这是我的代码:
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));
推荐答案
就像 Jimbo 在上面的评论中指出的那样,可以找到解决方案 这里
Like Jimbo pointed out in the comments above, the solution can be found here
根据文章,Windows PHP 发行版没有附带最新的 CA 根证书包.但是,可以在此处下载该捆绑包.我把它放在 C:\xampp\php\cacert.pem
下.
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
.
第二步是在 php.ini 文件的末尾添加 curl.cainfo=c:\xampp\php\cacert.pem
.更改保存 .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.
重启Apache,现在问题应该解决了!
Restart Apache and now the problem should be solved!
谢谢!
这篇关于Twitter API 在 XAMPP 上返回 NULL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!