Laravel Twitter Library - Where is the static function getUserTimeline()

fobus

I'm new in Laravel, I'm trying to understand how it works. I have setup this library as defined.

https://github.com/thujohn/twitter-l4

Examples works perfect when I define use with only Twitter; Shown below

    use Stream;
    use Twitter;

    class GoController extends \BaseController{
        function go($id){
             return Twitter::getUserTimeline(array('screen_name' => 'thujohn', 'count' => 20, 'format' => 'json'));
        }
}

but it throws this error when I use Thujohn\Twitter\Twitter;

    use Stream;
    use Thujohn\Twitter\Twitter;

    class GoController extends \BaseController{
        function go($id){
             return Twitter::getUserTimeline(array('screen_name' => 'thujohn', 'count' => 20, 'format' => 'json'));
        }
}

Non-static method Thujohn\Twitter\Twitter::getUserTimeline() should not be called statically, assuming $this from incompatible context

So, I'm unable to understand why I can't use the second form?

Damien Pirsy

Beacuse in the second example you're using the class directly, which happens to have the same name as the alias accessor.

What you see called statically is a Façade, which actually instantiates the class by using a static method (I'm not really good at explaining things...)

If you followed the instructions you should have created an Alias in the config/app.php file.

'Twitter' => 'Thujohn\Twitter\TwitterFacade',

And this alias is the very Twitter class (i.e., the façade) you need to call, and that you see called in the documentation.

So, remove the use statement use Thujohn\Twitter\Twitter; and your code will be using the "Twitter" alias (like it did in the first example), i.e. will call the Facade accessor.

 use Stream;

 class GoController extends \BaseController
 {

    public function go($id)
    {
      return \Twitter::getUserTimeline(array('screen_name' => 'thujohn', 'count' => 20, 'format' => 'json'));
    }
 }

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Laravel Twitter库-静态函数getUserTimeline()在哪里

来自分类Dev

getUserTimeLine(Twitter4J)仅适用于某些公共帐户

来自分类Dev

Static library test using XCTestCase

来自分类Dev

使用Laravel进行Twitter登录

来自分类Dev

GetUserTimeline总是返回我自己的时间线

来自分类Dev

Remove static library based on certain preprocessor macro

来自分类Dev

节点预gyp安装-后备构建--library = static_library

来自分类Dev

Laravel 4 Twitter Bootstrap 3的分页错误

来自分类Dev

Laravel 5.4 - Socialite Providers 与 Twitter 的多种配置

来自分类Dev

Laravel动态where子句

来自分类Dev

laravel Eloquent where子句

来自分类Dev

laravel whereraw与where语句

来自分类Dev

Laravel雄辩的WHERE和AND

来自分类Dev

多个where子句,Laravel

来自分类Dev

laravel雄辩的where子句

来自分类Dev

Laravel where子句timediff

来自分类Dev

Laravel Where 和 OrWhere

来自分类Dev

Laravel Eloquent Where With

来自分类Dev

Laravel with with where 口才

来自分类Dev

Laravel LengthAwarePaginator where 查询

来自分类Dev

或 where 子句 - Laravel 雄辩

来自分类Dev

laravel中where和or or Where之间的区别

来自分类Dev

Laravel雄辩或WHERE不为空

来自分类Dev

orWhere vs Where Laravel 5.1

来自分类Dev

Laravel 5.1动态where / orwhere

来自分类Dev

laravel 5.2嵌套Where子句

来自分类Dev

Laravel 在关系中的 WHERE 问题

来自分类Dev

Laravel 5.5 Collection where like

来自分类Dev

Laravel 雄辩的“with”和“where”多表