【问题标题】:how to implement friendships/exists in oriceon/oauth-5-laravel twitter api?如何在 oriceon/oauth-5-laravel twitter api 中实现友谊/存在?
【发布时间】:2016-01-29 20:41:20
【问题描述】:

我正在使用oriceon/oauth-5-laravel .help me 来实现 friendships/exists。我想发布关注特定人的请求。help me.tysm 前进

【问题讨论】:

    标签: oauth laravel-5 twitter-oauth


    【解决方案1】:

    考虑您想在 twitter 上关注 NASA 的情况。NASANASA 的网名。您应该将网名添加到网址如下。将此方法添加到您的控制器并进行正确的路由。

    public function followWithTwitter(Request $request)
    {
    
        $token  = $request->get('oauth_token');
        $verify = $request->get('oauth_verifier');
    
        $tw = \OAuth::consumer('Twitter');
        if ( ! is_null($token) && ! is_null($verify))
        {
            // This was a callback request from twitter, get the token
            $token = $tw->requestAccessToken($token, $verify);
            // Send a request with it
            $result = json_decode($tw->request('https://api.twitter.com/1.1/friendships/create.json?screen_name=NASA&follow=true','POST'), true);
            if (!$result){
                //do some tasks for calculating and database updation for following
                return ("failed");
            }
            else{
                //do some tasks for calculating and database updation for following
                return ("success");
            }
        }
        // if not ask for permission first
        else
        {
    
            // get request token
            $reqToken = $tw->requestRequestToken();
            // get Authorization Uri sending the request token
            $url = $tw->getAuthorizationUri(['oauth_token' => $reqToken->getRequestToken()]);
    
            // return to twitter login url
            return redirect((string)$url);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-22
      • 2017-03-20
      • 2015-07-01
      • 2016-03-31
      • 1970-01-01
      • 2013-11-04
      • 2013-01-27
      相关资源
      最近更新 更多