Exemplo n.º 1
0
 /**
  * 
  * Get list of people being followed
  * 
  */
 public function getFriends($nextCursor = -1)
 {
     // get members being followed on twitter
     $paramArr = ['screen_name' => $this->screenName, 'skip_status' => true, 'include_user_entities' => false, 'cursor' => $nextCursor, 'count' => 200];
     $r = \Twitter::getFriends($paramArr);
     if (!isset($r->users)) {
         throw new \Exception('users is not a property of twitter result');
     }
     $this->parseFriends($r->users);
     return $r->next_cursor_str;
 }
Exemplo n.º 2
0
 public function callback(Request $request)
 {
     // You should set this route on your Twitter Application settings as the callback
     // https://apps.twitter.com/app/YOUR-APP-ID/settings
     if (session()->has('oauth_request_token')) {
         $request_token = ['token' => session()->get('oauth_request_token'), 'secret' => session()->get('oauth_request_token_secret')];
         Tweet::reconfig($request_token);
         $oauth_verifier = false;
         if ($request->has('oauth_verifier')) {
             $oauth_verifier = $request->input('oauth_verifier');
         }
         // getAccessToken() will reset the token for you
         $token = Tweet::getAccessToken($oauth_verifier);
         if (!isset($token['oauth_token_secret'])) {
             return redirect()->route('twitter.login')->with('flash_error', 'We could not log you in on Twitter.');
         }
         $credentials = Tweet::getCredentials();
         if (is_object($credentials) && !isset($credentials->error)) {
             // $credentials contains the Twitter user object with all the info about the user.
             // Add here your own user logic, store profiles, create new users on your tables...you name it!
             // Typically you'll want to store at least, user id, name and access tokens
             // if you want to be able to call the API on behalf of your users.
             // This is also the moment to log in your users if you're using Laravel's Auth class
             // Auth::login($user) should do the trick.
             Auth::user()->update(['bio' => $credentials->description, 'twitter' => $credentials->screen_name]);
             $profile_image_url = file_get_contents(str_replace('_normal', '', $credentials->profile_image_url));
             $profile_banner_url = file_get_contents($credentials->profile_banner_url);
             $destinationPath = 'uploads/twitter';
             $profile_image = $destinationPath . '/twitter_profile_' . $credentials->screen_name . '.jpg';
             $profile_banner = $destinationPath . '/twitter_banner_' . $credentials->screen_name . '.jpg';
             file_put_contents($profile_image, $profile_image_url);
             file_put_contents($profile_banner, $profile_banner_url);
             $file1 = File::create(['url' => $profile_image, 'original_name' => 'twitter_profile_' . $credentials->screen_name, 'type' => 'profile_photo']);
             $file2 = File::create(['url' => $profile_banner, 'original_name' => 'twitter_banner_' . $credentials->screen_name, 'type' => 'profile_cover']);
             Auth::user()->files()->sync([$file1->id, $file2->id]);
             $twitter = Twitter::first();
             $twitter_data = ['user_id' => Auth::user()->id, 'token' => $token['oauth_token'], 'secret' => $token['oauth_token_secret'], 'twitter_id' => $token['user_id'], 'screen_name' => $token['screen_name']];
             is_null($twitter) ? Twitter::create($twitter_data) : Twitter::update($twitter_data);
             session()->put('access_token', $token);
             return redirect('admin/settings?tab=networks')->with('flash_notice', 'Congrats! You\'ve successfully signed in!');
         }
         return redirect()->route('twitter.error')->with('flash_error', 'Crab! Something went wrong while signing you up!');
     }
 }
 public function getTwitterJson()
 {
     return \Twitter::getUserTimeline(['screen_name' => $this->handle, 'count' => $this->count, 'format' => 'json']);
 }