Fatal error: Class 'Response' not found

Fatal error: Class 'Response' not found

我正在与 Abraham 的 twitteroauth 合作,在我的应用程序中实施 Twitter OAuth。 运行 我的应用程序,这是我遇到的错误:

Fatal error: Class 'Response' not found in /opt/lampp/htdocs/tmhOAuth-master/twitteroauth.php on line 108

现在,这是我的 twitteroauth.php 文件直到第 108 行的样子:

<?php
/**
 * The most popular PHP library for use with the Twitter OAuth REST API.
 *
 * @license MIT
 */
//namespace twitteroauthm\src\TwitterOAuth;
//use twitteroauthm\src\TwitterOAuth;
use twitteroauthm\src\Util\JsonDecoder;

require "twitteroauthm/autoload.php";
use Abraham\TwitterOAuth\TwitterOAuth as Config;
//require_once("twitteroauthm/src/TwitterOAuth.php");

//use twitteroauthm\src\TwitterOAuth;

//require_once("twitteroauthm/src/Config.php");

/**
 * TwitterOAuth class for interacting with the Twitter API.
 *
 * @author Abraham Williams <abraham@abrah.am>
 */
class TwitterOAuth extends Config
{
    const API_VERSION = '1.1';
    const API_HOST = 'https://api.twitter.com';
    const UPLOAD_HOST = 'https://upload.twitter.com';

    /** @var Response details about the result of the last request */
    private $response;
    /** @var string|null Application bearer token */
    private $bearer;
    /** @var Consumer Twitter application details */
    private $consumer;
    /** @var Token|null User access token details */
    private $token;
    /** @var HmacSha1 OAuth 1 signature type used by Twitter */
    private $signatureMethod;

    /**
     * Constructor
     *
     * @param string      $consumerKey      The Application Consumer Key
     * @param string      $consumerSecret   The Application Consumer Secret
     * @param string|null $oauthToken       The Client Token (optional)
     * @param string|null $oauthTokenSecret The Client Token Secret (optional)
     */
    public function __construct($consumerKey, $consumerSecret, $oauthToken = null, $oauthTokenSecret = null)
    {
        $this->resetLastResponse();
        $this->signatureMethod = new HmacSha1();
        $this->consumer = new Consumer($consumerKey, $consumerSecret);
        if (!empty($oauthToken) && !empty($oauthTokenSecret)) {
            $this->token = new Token($oauthToken, $oauthTokenSecret);
        }
        if (empty($oauthToken) && !empty($oauthTokenSecret)) {
            $this->bearer = $oauthTokenSecret;
        }
    }

    /**
     * @param string $oauthToken
     * @param string $oauthTokenSecret
     */
    public function setOauthToken($oauthToken, $oauthTokenSecret)
    {
        $this->token = new Token($oauthToken, $oauthTokenSecret);
    }

    /**
     * @return string|null
     */
    public function getLastApiPath()
    {
        return $this->response->getApiPath();
    }

    /**
     * @return int
     */
    public function getLastHttpCode()
    {
        return $this->response->getHttpCode();
    }

    /**
     * @return array
     */
    public function getLastXHeaders()
    {
        return $this->response->getXHeaders();
    }

    /**
     * @return array|object|null
     */
    public function getLastBody()
    {
        return $this->response->getBody();
    }

    /**
     * Resets the last response cache.
     */
    public function resetLastResponse()
    {
        $this->response = new Response();
    }

我的代码似乎有什么问题?有没有办法将我不知道的 Response class 包含到我的文件中?

我还提供了一些屏幕截图来概述我的项目的文件结构:

因为您正在使用命名空间,请在顶部添加 'use Response',至于目前您的回复 class 无法识别

与您使用 Confing 的方式相同,只需确保识别到 Response class 的链接即可。

use Abraham\TwitterOAuth\TwitterOAuth as Config;
use Abraham\TwitterOAuth\Response as Response;

或尝试将其包含在顶部:

require_once('your_path/Response.php');