skip to Main Content

Is it possible to send automatic tweets from laravel like user.
User must be logged by my twitter API, and then can I send tweet as him?Of course he must accept this action. I must know when user tweets my page.
Can it work like facebook share? Is there tools for this?

Sorry for my english.
Thanks for all answer.

PS.
I do not mean this package http://vegibit.com/send-a-tweet-with-laravel/ .
I need send tweets to user table.

2

Answers


  1. Use this https://twitteroauth.com/ package.

    Push in your console composer require abraham/twitteroauth
    When all installed then you should add
    use AbrahamTwitterOAuthTwitterOAuth; to your class.

    Now in function you must create connection with your api.

    $connection = new TwitterOAuth(
    CONSUMER_KEY, // Information about your twitter API
    CONSUMER_SECRET, // Information about your twitter API
    $access_token, // You get token from user, when him  sigin to your app by twitter api
    $access_token_secret// You get tokenSecret from user, when him  sigin to your app by twitter api
    );
    

    If you created connection then you can send post as user.
    For example:

    $connection->post("statuses/update", ["status" => "My first post!"]);
    
    Login or Signup to reply.
  2. I have found the ThuJohn package to be the winner at this type of work.
    https://github.com/thujohn/twitter
    Simple to use with various options, such as

    Send a tweet realtime without media:

    Route::get('/send-tweet-no-media', function()
    {
        return Twitter::postTweet(['status' => 'Laravel is beautiful', 'format' => 'json']);
    });
    

    Send a tweet realtime with media:

    Route::get('/send-tweet-with-media', function()
    {
        $uploaded_media = Twitter::uploadMedia(['media' => File::get(public_path('filename.jpg'))]);
        return Twitter::postTweet(['status' => 'Laravel is beautiful', 'media_ids' => $uploaded_media->media_id_string]);
    });
    

    You can also do various other things, such as login, You can take it an extra level and easily store the users token & secret to your users table and do scheduled posts.

    Once you have stored the users token & secret you can tweet scheduled posted for them like this:

    //Get the Users token & from your User Table (or where ever you stored them)
    $token = $user->token;
    $secret = $user->secret;
    
    //This line resets the token & secret with the users        
    Twitter::reconfig(['token' => $token, 'secret' => $secret]);
    
    //This line posts the tweet as the user
    Twitter::postTweet(['status' => 'test', 'format' => 'json']);       
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search