2016-01-13 75 views

回答

2

考慮要遵循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); 
    } 
}