2015-02-07 70 views
2

我用THIS twitter librabry得到这个错误。任何人都可以告诉我哪里出错了吗?找不到类别PHP

错误

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 
?> 
+0

你可以看看这个问题和它的答案http://stackoverflow.com/questions/27745553/php-include-doesnt-work-for-twitteroauth-php-but-when-i-copy-and-paste-its-con?rq = 1 – 2015-02-07 19:27:12

+0

@Esteban现在错误显示为' {“错误“:[{”message“:”无法验证你“,”代码“:32}]}' – 2015-02-07 19:49:11

回答

5

你确定这是正确的做法? :

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

你可以尝试:

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

now'致命错误:类'TwitterOAuth'在第36行的D:\ wamp \ www \ test.php中找不到' – 2015-02-07 19:40:43

+0

:-)尝试我更新的答案:-) – Alex 2015-02-07 20:17:50

+0

它的工作感谢 – 2015-02-08 07:02:13

0

TwitterOAuth使用Config类 - 但它不会自动加载。您可以使用require这个类 - 或者使用类加载器。最好的方法是使用composer来管理你的依赖关系(它带有一个类加载器)。

+0

有一个composer.json文件,但如何使用它? @fateddy – 2015-02-07 19:37:33

0

你能检查 vendor\abraham\twitteroauth\src

是否有Config.php

我遇到这个问题的原因是由一个.gitignore放在项目的上方。这一个是包含一行config.php ... 我改变它为\config.php删除只有顶级配置文件,并启用亚伯拉罕的库文件