[英]PHP Fatal error: Class 'OAuth'
I searched the site for hours looking for answer and nothing helped me.我在网站上搜索了几个小时寻找答案,但没有任何帮助。 I've installed PHP/Apache2/PECL/OAuth and edited php.ini for
extension=oauth
.我已经安装了 PHP/Apache2/PECL/OAuth 并为
extension=oauth
编辑了 php.ini 。 I get this error everything I type "php example.php" I'd set the token and everything required in example.php我收到这个错误我输入“php example.php”的所有内容我会设置令牌和example.php中所需的所有内容
PHP Fatal error: Class 'OAuth' not found in /home/twitter/TwitterAutoReply.php on line 22
PHP 致命错误:在第 22 行的 /home/twitter/TwitterAutoReply.php 中找不到“OAuth”类
My php files is example.php and TwitterAutoReply.php我的 php 文件是 example.php 和 TwitterAutoReply.php
https://raw.github.com/gist/820281/303a61ee9b324070e803e51806552e64fccfdd4c/example.php and https://gist.github.com/raw/820281/6bf1b6d78dd05daef319ce84a88eedf139a44b5a/TwitterAutoReply.php https://raw.github.com/gist/820281/303a61ee9b324070e803e51806552e64fccfdd4c/example.php和https://gist.github.com/raw/820281/6bf1b6d78edd05daef3189eRep45daef3189eRep55daef3806552e64fccfdd4c/example.php
From the error, you're not importing the oauth package in you php.ini file.从错误中,您没有在 php.ini 文件中导入 oauth 包。 For ubuntu, you need to install oauth:
对于 ubuntu,您需要安装 oauth:
sudo pecl install oauth
Then include the oauth package in your php.ini.然后在 php.ini 中包含 oauth 包。 If you don't know where the file is, you can use:
如果您不知道文件在哪里,可以使用:
sudo find / -name "oauth.so"
Using the path to the extension add the following to your php.ini:使用扩展名的路径将以下内容添加到您的 php.ini 中:
extension=/path/to/oauth/package/oauth.so
Restart apache and try again.重新启动 apache 并重试。
Ensure that the extension is actually loaded.确保实际加载了扩展。 To verify that it is, simply ask PHP something about the OAuth extension, in a command like:
要验证它是否正确,只需在如下命令中向 PHP 询问有关 OAuth 扩展的信息:
php --re oauth
If this doesn't show information about the module but instead gives an error, you'll know that it's not loaded.如果这没有显示有关模块的信息而是给出错误,您就会知道它没有加载。 Additionally you could simply list all loaded modules with
php -m
.此外,您可以简单地使用
php -m
列出所有加载的模块。
Try manually loading the extension by using -z oauth
in your command.尝试在命令中使用
-z oauth
手动加载扩展。 Example: php -z oauth example.php
.示例:
php -z oauth example.php
。 If that works, you didn't edit your php.ini correctly.如果可行,则说明您没有正确编辑 php.ini。
The command php --re oauth
solved my issue.命令
php --re oauth
解决了我的问题。
Seems there was some miss coding with php.ini
.似乎有一些使用
php.ini
编码的错误。 the command gives me error, I removed those lines and re-install oauth, restarted httpd and it loads that extension successfully.该命令给了我错误,我删除了这些行并重新安装了 oauth,重新启动了 httpd 并成功加载了该扩展。
I was working on oauth client and in the situation without an ability to change the environment (add php-oauth extension).我在 oauth 客户端上工作,在无法改变环境的情况下(添加 php-oauth 扩展)。 the following solution worked out for me:
以下解决方案对我有用:
1) install Zend OAuth 1) 安装 Zend OAuth
composer require zendframework/zendoauth
2)using the following in PHP code: 2)在PHP代码中使用以下内容:
$hmac = new \\ZendOAuth\\Signature\\Hmac($consumerSecret, $accessTokenSecret, 'SHA1'); return $hmac->sign($data, $method, $url);
instead of代替
$oauth = new OAuth(... $oauth->generateSignature(...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.