致命错误:等级'回复'未找到

时间:2015-08-18 06:39:04

标签: php twitter oauth oauth-2.0 twitter-oauth

我正在与亚伯拉罕的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类包含在我不知道的文件中?

我还包括一些截图,以概述我项目的文件结构:

enter image description here

enter image description here

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:1)

当您使用命名空间时,请添加&#39;使用响应&#39;在顶部,目前您的响应类未被识别

与使用Confing的方式相同,只需确保将识别linke到Response类。

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

或尝试将其包含在顶部:

require_once('your_path/Response.php');