php 致命错误:找不到类“OAuth”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13822406/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fatal error: Class 'OAuth' not found in
提问by Lehan Coetzee
I'm trying to connect to the LinkedIn API but everytime I try to access it I get the following error:
我正在尝试连接到 LinkedIn API,但每次尝试访问它时都会出现以下错误:
Fatal error: Class 'OAuth' not found in /home/vhosts/*/test.php on line 8
致命错误:在第 8 行的/home/vhosts/ */test.php 中找不到“OAuth”类
I'm using a free server on 000WebHost and I've read that free servers sometimes don't support OAuth. I've tried it on another free server and I get the same error message, so my question is how can I check whether the server supports the use of OAuth?
我在 000WebHost 上使用免费服务器,我读到免费服务器有时不支持 OAuth。我已经在另一台免费服务器上尝试过,但收到相同的错误消息,所以我的问题是如何检查服务器是否支持使用 OAuth?
Here is my code:
这是我的代码:
// 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();
The keys are just replaced with the ones on the LikedIn Developers Getting Started Guide.
密钥只是替换为 LikedIn 开发人员入门指南中的密钥。
Thank you in advance for your help.
预先感谢您的帮助。
采纳答案by cryptic ツ
OAuth is a PECL extension it must be compiled into PHP or compiled as an extension.
OAuth 是 PECL 扩展,它必须编译成 PHP 或编译为扩展。
Most servers will not have it by default since it really is not something everyone would likely use. You can ask your host to either install it or if you have the ability compile it on server if using CGI as I did. If you run phpinfo(); and look for the word OAuth it will show up if you have it, otherwise you don't.
大多数服务器默认情况下不会有它,因为它确实不是每个人都可能使用的。如果像我一样使用 CGI,您可以要求您的主机安装它,或者您是否有能力在服务器上编译它。如果你运行 phpinfo(); 并寻找 OAuth 这个词,如果你有它,它就会显示出来,否则你不会。
Update:Use https://github.com/Lusitanian/PHPoAuthLibinstead of a PECL.
更新:使用https://github.com/Lusitanian/PHPoAuthLib而不是 PECL。
回答by zfb
I use hostgator for hosting and was having this problem so if your host also uses cpanel you should be able to do what I did.
我使用hostgator进行托管并且遇到了这个问题,所以如果你的主机也使用cpanel你应该能够做我所做的。
Go 1 directory up from the live directory in File Manager where you can see "public_html, www, tmp". (Or click the home folder icon to the left) and in there you should find a php.ini file. edit the file adding extension=oauth.soto the very end and save it.
从文件管理器中的实时目录向上移动 1 个目录,您可以在其中看到“public_html、www、tmp”。(或单击左侧的主文件夹图标),您应该在其中找到一个 php.ini 文件。编辑添加extension=oauth.so到最后的文件并保存。
Checking phpinfo() after that you should find a section called "OAuth" and everything should work fine.
之后检查 phpinfo() 你应该找到一个名为“OAuth”的部分,一切都应该正常工作。
回答by jbobbins
For php 5.6... First the disclaimer: you need to migrate to the latest stable php 7 ASAP and notrun php 5.6! But if that's just not possible quite yet, this might help Ubuntu 16.04 users. This assumes you have the ondrej/php ppa.
对于 php 5.6 ... 首先是免责声明:您需要尽快迁移到最新的稳定版 php 7,而不是运行 php 5.6!但如果这还不太可能,这可能会对 Ubuntu 16.04 用户有所帮助。这假设您有 ondrej/php ppa。
sudo apt-get update
sudo apt-get install libpcre3-dev
sudo apt-get install php-pear # * see note below
sudo apt-get install php5.6-dev # for phpize
sudo pecl install oauth-1.2.3
# now add "extension=oauth.so" (sans quotes) to the
# "Dynamic Extensions" area in /etc/php/5.6/apache2/php.ini
* Per this post https://askubuntu.com/a/756186/343695"php-pear pull[s] just CLI PHP 7.0 (php7.0-cli) and that's harmless" That comment was made in 2016 and may no longer be true. I didn't see any problems...yet.
* 根据这篇文章 https://askubuntu.com/a/756186/343695“php-pear pull[s] just CLI PHP 7.0 (php7.0-cli) and that's无害” 该评论是在 2016 年发表的,可能不再是真实的。我没有看到任何问题......还没有。

