简体   繁体   中英

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 . I get this error everything I type "php example.php" I'd set the token and everything required in example.php

PHP Fatal error: Class 'OAuth' not found in /home/twitter/TwitterAutoReply.php on line 22

My php files is example.php and TwitterAutoReply.php

https://raw.github.com/gist/820281/303a61ee9b324070e803e51806552e64fccfdd4c/example.php and https://gist.github.com/raw/820281/6bf1b6d78dd05daef319ce84a88eedf139a44b5a/TwitterAutoReply.php

From the error, you're not importing the oauth package in you php.ini file. For ubuntu, you need to install oauth:

sudo pecl install oauth

Then include the oauth package in your php.ini. 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:

extension=/path/to/oauth/package/oauth.so

Restart apache and try again.

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 --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 .

Try manually loading the extension by using -z oauth in your command. Example: php -z oauth example.php . If that works, you didn't edit your php.ini correctly.

The command php --re oauth solved my issue.

Seems there was some miss coding with php.ini . the command gives me error, I removed those lines and re-install oauth, restarted httpd and it loads that extension successfully.

I was working on oauth client and in the situation without an ability to change the environment (add php-oauth extension). the following solution worked out for me:

1) install Zend OAuth

composer require zendframework/zendoauth

2)using the following in PHP code:

$hmac = new \\ZendOAuth\\Signature\\Hmac($consumerSecret, $accessTokenSecret, 'SHA1'); return $hmac->sign($data, $method, $url);

instead of

$oauth = new OAuth(... $oauth->generateSignature(...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM