【问题标题】:Class not found PHP找不到类 PHP
【发布时间】:2016-10-23 03:57:53
【问题描述】:

我使用THIS twitter librabry 并收到此错误。谁能告诉我哪里出错了?

错误

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

【问题讨论】:

标签: php class twitter directory twitter-oauth


【解决方案1】:

你确定这是正确的方法吗? :

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

你可以试试:

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

【讨论】:

  • 现在Fatal error: Class 'TwitterOAuth' not found in D:\wamp\www\test.php on line 36
【解决方案2】:

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

【讨论】:

  • 有一个composer.json文件但是如何使用呢? @fateddy
【解决方案3】:

你能检查一下你的 vendor\abraham\twitteroauth\src

Config.php吗?

我遇到这个问题的原因是在项目中放置了一个.gitignore。这个包含一行config.php ... 我将其更改为 \config.php 以仅删除顶部配置文件并在 abraham 的库中启用该文件

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-02-25
    • 2017-05-24
    • 2015-04-04
    • 2021-09-20
    • 2012-05-04
    • 2012-02-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多