Fatal error: Class 'Abraham\TwitterOAuth\Config' not found in …
Hi,
I've been going through loads of previous issues here to try and see if they could help with trying to get this to work for me, but I'm stumped. Sorry, I'm not a php dev, so I'm using the manual method as described :-(
require "twitteroauth/autoload.php";
use Abraham\TwitterOAuth\TwitterOAuth;
The full error is:
Fatal error: Class 'Abraham\TwitterOAuth\Config' not found in /var/www/vhosts/stagingtesting.com/subdomains/redtree.stagingtesting.com/wp-content/themes/redtree/includes/twitter/twitteroauth/src/TwitterOAuth.php on line 17
So I'm guessing I'm having paths issues.
It's a Wordpress site, so in footer.php I've got this:
<?php get_template_part('includes/twitter/get-tweets'); ?>
And it's in this get-tweets.php file that I'm requiring Twitteroauth as above. My twitteroauth directory is at the same level as this php file and the files are extracted as you described. I did a print_r on $base_dir in autoload.php and it returns this which I presume is not correct:
/var/www/vhosts/stagingtesting.com/subdomains/redtree.stagingtesting.com/wp-content/themes/redtree/includes/twitter/twitteroauth/src//var/www/vhosts/stagingtesting.com/subdomains/redtree.stagingtesting.com/wp-content/themes/redtree/includes/twitter/twitteroauth/src/
The path is double stacked.
One other thing to note is that it works on my local MAMP using php 7.1.0 but not on the live site with Shared hosting PHP 7.1 CGI (7.1.6).
Any thoughts on what's happening here? Sorry, I know you've been queried about this issue many times.
Thanks!
What is the value of __DIR__ and $relative_class in autoload.php?
I'm getting them both printing out twice as:
DIR = /var/www/vhosts/stagingtesting.com/subdomains/redtree.stagingtesting.com/wp-content/themes/redtree/includes/twitter/twitteroauth
REALTIVE CLASS = TwitterOAuth
DIR = /var/www/vhosts/stagingtesting.com/subdomains/redtree.stagingtesting.com/wp-content/themes/redtree/includes/twitter/twitteroauth
REALTIVE CLASS = Config
$base_dir = __DIR__ . '/src/'; so I'm not sure how that would get the path twice as you originally mentioned.
Yeah, there's nothing in a loop etc.
I assume it shouldn't print out 2 relative classes either?
I think having things print twice isn't a problem. It's not ideal to have the same code run twice but requiring a file multiple times won't break things. If the value printed once is a single string with the path twice than that is an issue.
I don't suppose you would have any idea what might cause that if this is the issue?
Try adding use Abraham\TwitterOAuth\Config as Config; after namespace Abraham\TwitterOAuth; in src/TwitterOAuth.php
Unfortunately that gives the error:
Fatal error: Class 'Abraham\TwitterOAuth\Config' not found in /var/www/vhosts/stagingtesting.com/subdomains/redtree.stagingtesting.com/wp-content/themes/redtree/includes/twitter/twitteroauth/src/TwitterOAuth.php on line 18
What version of PHP are you running?
I have the same issue. Let us know if there is a solution to this problem.
I made the new object as \Abraham\TwitterOAuth\TwitterOAuth. Before I use to make it like $connection = new TwitterOAuth and now changed it to $connection = new \Abraham\TwitterOAuth\TwitterOAuth.
This solved my problem. It was because of the namespaces thing.
If you have use Abraham\TwitterOAuth\TwitterOAuth; this shouldn't be an issue. You might have a different issue from @petebarr.
What version of PHP are you using?
7.1.8
Sorry abraham, my fault. I didn't realise that a prev developer had a gitignore on the Config file so it was missing. I hate my life! lol. Cheers for your help anyway, much appreciated!
Similar issue here. I had a rule in Transmit to skip files named "config.php". Apparently it isn't case-sensitive. All sorted now.
same here

Whats the issue for this error?
You're not following the installation instructions on https://twitteroauth.com/.
You should either use composer to install and load TwitterOAuth like this:
require "vendor/autoload.php";
use Abraham\TwitterOAuth\TwitterOAuth;
or download the files manually and load TwitterOAuth like this:
require "twitteroauth/autoload.php";
use Abraham\TwitterOAuth\TwitterOAuth;