Post to twitter

Hi,

I'd like to have a checkbox under my wire posts where we could send our posts to twitter. Has anyone had any luck doing this with 1.8?

Thanks,

Hairy Larry

  • twitter_api auth is a core plugin, so all you really need is to find a php class for twitter and write a few lines of code.

  • You can use the same twitter API of the core. The users who are already using twitter_api to login to your site, can directly send their wire posts to twitter with a little coding. For other user, they need to have to authenticate their elgg account with twitter first. Anyway you have to do a bit of code yourself..

  • I haven't got the twitter_api plugin to work with 1.8. Are any others having luck with it? Maybe it's something I'm doing wrong.

    That would be the first step. Then it would still have to be coded to forwarded a post to twitter.

    I have been extending embed_extender but I have no experience writing plugins. I am an experienced php programmer and I'm always interested in learning something new.

     

  • Have you gone thru this in yr 1.8 install ?

    Plugin Settings

    Twitter API

    You must obtain a consumer key and secret from Twitter. Fill out the new app application. Select "Browser" as the application type and "Read & Write" for the access type. The callback url is http://localhost/elgg1810/twitter_api/authorize.

     

  • I think this would do the job (haven't tested, just wrote down the code):

    start.php

    <?php

    /* hypeWireTweet

     *

     * @package hypeJunction

     * @subpackage hypeWireTweet

     *

     * @author Ismayil Khayredinov <ismayil.khayredinov@gmail.com>

     * @copyright Copyrigh (c) 2011, Ismayil Khayredinov

     */

    elgg_register_event_handler('init', 'system', 'hj_wiretweet_init');

    function hj_wiretweet_init() {

        elgg_extend_view('forms/thewire/add', 'hj/wiretweet/select', 1);

        elgg_register_plugin_hook_handler('status', 'user', 'hj_wiretweet_send_to_twitter');

    }

    function hj_wiretweet_send_to_twitter($hook, $type, $return, $params) {

        $entity = elgg_extract('entity', $params, null);

        if (elgg_instanceof($entity, 'object', 'thewire') && get_input('send_wire_to_twitter')) {

    $token = twitter_api_get_access_token();

    $return['twitter_response'] = $token->post('statuses/update', array(

       'status' => $entity->description // ref: thewire_save_post()

    ));

        }

        return $return;

    }

     

    select.php

     <?php

     

    $username = elgg_get_plugin_user_setting('twitter_name', 'twitter_api');

    $key = elgg_get_plugin_user_setting('access_key', 'twitter_api');

    $secret = elgg_get_plugin_user_setting('access_secret', 'twitter_api');

     

    if ($username && $key && $secret) {

     

        echo elgg_view('input/checkbox', array(

    'name' => 'send_wire_to_twitter',

    'options' => array(elgg_echo('hj:wiretweet:sendwiretotwitter') => true)

        ));

     

    }

     

  • DhrupDeScoop,

    Thanks for the help. I didn't find anyplace to set the application type to browser but I did everything else you suggested and I got it to work. I also had to activate the OAuth plugin but that was explained in the twitter api plugin more info.

    Ismayil Khayredinov

    I haven't had time to try your code yet but I will. So do I have to install a hypeJunction plugin? I notice it's listed as a package in the comments. So basically the whole plugin will be two files, start.php and select.php? I am totally new to programming plugins but I do code php and I have done a bit of api work.

    Thanks,

    Hairy Larry

  • Larry, no extra plugins will be necessary (twitter_api and oauth_api should be enabled). Technically it's 3 files, you will need to include manifest.xml as well.

  • Thanks Ismayil. I'm going to try it and see if I can get it to work. Hairy Larry

  • Just an update. I have been working with Ismayil's code with his help by email. Learning a lot about programming plugins. I have the checkbox working but I'm not pushing the tweet to twitter.

    Anyone with specific experience of how to do this?

    I will update again later.

    Thanks,

    Hairy Larry

  • Larry,

    Open your console (right click -> inspect element). Choose network. When you save the wire post, you will see add in the list of documents. Look into what parameters are being sent to the form (that will be all the data from your form). Make sure send_wire_to_twitter is sent as well. If it's not sent, then your checkbox is outside of <form></form>.

    If the value is sent, then we need to look into the plugin_hook_handler. Something is not being processed there properly.

Feedback and Planning

Feedback and Planning

Discussions about the past, present, and future of Elgg and this community site.