我正在尝试连接到 LinkedIn API,但每次我尝试访问它时都会收到以下错误:
Fatal error: Class 'OAuth' not found in /home/vhosts/*/test.php on line 8
我在 000WebHost 上使用免费服务器,我了解到免费服务器有时不支持 OAuth。我在另一台免费服务器上尝试过,但收到了相同的错误消息,所以我的问题是如何检查服务器是否支持使用 OAuth?
这是我的代码:
// Fill the keys and secrets you retrieved after registering your app
$oauth = new OAuth("abcd123456", "efgh987654");
$oauth->setToken("abcd1234-efgh987-9988", "9876abcd-123asdf-1122");
$params = array();
$headers = array();
$method = OAUTH_HTTP_METHOD_GET;
// Specify LinkedIn API endpoint to retrieve your own profile
$url = "http://api.linkedin.com/v1/people/~";
// By default, the LinkedIn API responses are in XML format. If you prefer JSON, simply specify the format in your call
// $url = "http://api.linkedin.com/v1/people/~?format=json";
// Make call to LinkedIn to retrieve your own profile
$oauth->fetch($url, $params, $method, $headers);
echo $oauth->getLastResponse();
key 只是替换为 LikedIn 开发人员入门指南中的 key 。
预先感谢您的帮助。
最佳答案
OAuth 是 PECL 扩展,必须编译成 PHP 或编译为扩展。
大多数服务器默认情况下不会有它,因为它确实不是每个人都可能使用的东西。您可以要求您的主机安装它,或者如果您像我一样使用 CGI,是否有能力在服务器上编译它。如果你运行 phpinfo();并查找 OAuth 一词,如果有,它会显示,否则不会显示。
更新:使用https://github.com/Lusitanian/PHPoAuthLib而不是 PECL。
关于php - fatal error : Class 'OAuth' not found in,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13822406/