Class not found PHP

爱⌒轻易说出口 提交于 2019-12-24 03:21:14

问题


I used THIS twitter librabry and getting this error. Can anyone tell where i am going wrong ?

ERROR

Fatal error: Class 'Abraham\TwitterOAuth\Config' not found in D:\wamp\www\Abraham\TwitterOAuth\TwitterOAuth.php on line 17

PHP

<?php

require_once("Abraham/TwitterOAuth/TwitterOAuth.php"); //Path to twitteroauth library you downloaded in step 3

//keys and tokens initialised


function getConnectionWithAccessToken($cons_key, $cons_secret, $oauth_token, $oauth_token_secret) {
  $connection = new TwitterOAuth($cons_key, $cons_secret, $oauth_token, $oauth_token_secret);
  return $connection;
}

$connection = getConnectionWithAccessToken($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);

$tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$twitteruser."&count=".$notweets);

echo json_encode($tweets);
echo $tweets; //testing remove for production   
?>

回答1:


Are you sure that this is correct way? :

require_once("Abraham/TwitterOAuth/TwitterOAuth.php");

you could try:

require_once("Abraham/autoload.php"); 
require_once("Abraham/TwitterOAuth/TwitterOAuth.php"); 
use Abraham\TwitterOAuth\TwitterOAuth;



回答2:


TwitterOAuth uses the Config class - but it does not get loaded automatically. You could require this class - or use a classloader. The best approach would be using composer to manage your dependencies (which comes with a class loader).




回答3:


Could you check your vendor\abraham\twitteroauth\src :

Is there a Config.php ?

I encountered this problem causes by a .gitignore placed upper in the project. This one was containing a line config.php ... I changed it to \config.php to remove only the top config file and enable the file in abraham's library



来源:https://stackoverflow.com/questions/28386315/class-not-found-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!