Lehan Coetzee
Lehan Coetzee

Reputation: 424

Fatal error: Class 'OAuth' not found in

I'm trying to connect to the LinkedIn API but everytime I try to access it I get the following error:

Fatal error: Class 'OAuth' not found in /home/vhosts/*/test.php on line 8

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?

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.

Thank you in advance for your help.

Upvotes: 11

Views: 36752

Answers (4)

Serhii Vasko
Serhii Vasko

Reputation: 443

sudo apt-get update
sudo apt-get install php-oauth
sudo service apache2 restart

Upvotes: 2

jbobbins
jbobbins

Reputation: 1291

For php 5.6... First the disclaimer: you need to migrate to the latest stable php 7 ASAP and not run 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.

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.

Upvotes: 0

Tony
Tony

Reputation: 744

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.

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.so to the very end and save it.

Checking phpinfo() after that you should find a section called "OAuth" and everything should work fine.

Upvotes: 2

kittycat
kittycat

Reputation: 15045

OAuth is a PECL extension it must be compiled into PHP or compiled as an extension.

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.


Update: Use https://github.com/Lusitanian/PHPoAuthLib instead of a PECL.

Upvotes: 11

Related Questions