Github API在本地主机上没有返回任何东西,设置丢失


Github API is returning nothing on localhost, settings missing?

对于PHP项目,我一直想根据用户提供的反馈向Github项目添加问题。然而,我只是从Github API获得一些东西。下面的命令行给出了我期望得到的信息:

$ curl -u <username> https://api.github.com/user

这给了我我的用户信息,但当我尝试在PHP我只是得到黑页。我的代码是:

<?php
$ch     = curl_init();
curl_setopt( $ch, CURLOPT_URL, 'https://api.github.com/user' );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_USERPWD, "<username>:<password>" );
curl_setopt( $ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC );
$output = curl_exec( $ch );
$info   = curl_getinfo( $ch );
curl_close( $ch );
echo $output;
var_dump( $info );
?>

我怀疑$输出与我在命令行中得到的相同,但这里它是空的。我得到的是$info:

array(26) { ["url"]=> string(27) "https://api.github.com/user" ["content_type"]=> NULL ["http_code"]=> int(0) ["header_size"]=> int(0) ["request_size"]=> int(0) ["filetime"]=> int(-1) ["ssl_verify_result"]=> int(0) ["redirect_count"]=> int(0) ["total_time"]=> float(0.203) ["namelookup_time"]=> float(0.015) ["connect_time"]=> float(0.109) ["pretransfer_time"]=> float(0) ["size_upload"]=> float(0) ["size_download"]=> float(0) ["speed_download"]=> float(0) ["speed_upload"]=> float(0) ["download_content_length"]=> float(-1) ["upload_content_length"]=> float(-1) ["starttransfer_time"]=> float(0) ["redirect_time"]=> float(0) ["redirect_url"]=> string(0) "" ["primary_ip"]=> string(14) "192.30.252.136" ["certinfo"]=> array(0) { } ["primary_port"]=> int(443) ["local_ip"]=> string(13) "192.168.0.109" ["local_port"]=> int(28935) } 

我在PHP中找不到任何简单的例子,我不想用整个框架来做一些应该如此简单的事情。从我从API文档中得到的,我应该能够发送我的凭据,然后获得信息。

我可能错过了一些明显的东西,但不能弄清楚,谁能给我指出正确的方向?

我一直在寻找,并在另一个API的github项目上发现了这个问题。如果不包含

,则在本地工作时,curl确实返回空值。
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );

在那之后,我得到了我丢失了一个用户代理的消息,在包含了这个之后,它工作了。在上传原始代码到我的网站托管后,我首先得到丢失的用户代理消息。

希望我能帮到别人。