尝试使用php连接到twitter api。使用以下github发行版中的文件:https://github.com/abraham/twitteroauth。我只是得到500服务器错误并尝试使用error_reporting(E_ALL)但无济于事。不确定是什么,这是我的代码:
<?php
session_start();
require_once("twitteroauth-master/src/TwitterOAuth.php");
$apikey="not included but definitely correct";
$apisecret="not included but definitely correct";
$accesstoken="not included but definitely correct";
$accesssecret="not included but definitely correct";
$connection = new TwitterOAuth($apikey, $apisecret, $accesstoken, $accesssecret);
print_r($connection);
?>
答案 0 :(得分:0)
添加此作为答案,因为评论太长,我怀疑是问题。根据文档(https://twitteroauth.com),当不使用Composer时,您需要包含自动加载文件。这是根据您当前的代码看起来的样子:
<?php
session_start();
// Require the autoload file. It registers an autoloader to
// know how to access the project's files
require_once("twitteroauth-master/autoload.php");
// A use statement so you don't need to use the full namespace
use Abraham\TwitterOAuth\TwitterOAuth as TwitterOAuth;
$apikey="not included but definitely correct";
$apisecret="not included but definitely correct";
$accesstoken="not included but definitely correct";
$accesssecret="not included but definitely correct";
$connection = new TwitterOAuth($apikey, $apisecret, $accesstoken, $accesssecret);
print_r($connection);
?>
500错误很可能是因为它没有找到TwitterOAuth
类。您的设置可能未正确配置以显示错误,这是一个完全不同的问题。你可以在这里阅读一些解决方案:How do I get PHP errors to display?
500错误的另一种可能性是require_once
失败。如果上述代码不起作用,请尝试使用./