Ad Widget

Collapse

Media Type: Twitter DM

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Voxie
    Junior Member
    • Jul 2009
    • 24

    #1

    Media Type: Twitter DM

    I have create a media type to sent notification as DM on Twitter.

    Before you can use this script you have to create a twitter app and get the secret and acccess key from the account where you want to sent messages from.

    In the profile of the user you set the twitter-account you want to sent a message to.
    The sender has to follow that twitter account and that twitter account needs to follow you.


    It uses the default twitteroauth files that you can download from twitter.
    You have to download it and put it a folder called twitteroauth in the same directory as this script.

    Code:
    #!/usr/bin/php
    <?php
     
    /* Load required lib files. */
    session_start();
    
    require_once('twitteroauth/twitteroauth.php');
    require_once('twitteroauth/config.php');
    
    
    //acceskey and secret.
    $access = "<your access>";
    $secret = "<your secret>";
    
    
    if (count($argv)<3) {
        die ("Usage: ".$argv[0]." recipient \"subject\" \"message\"\n");
    }
    
    if ( $debug )
        file_put_contents($logfilelocation."twitter_alert_".date("YmdHis"), serialize($argv));
    
    $to         = $argv[1];
    $subject    = $argv[2];  // not being used
    $message    = $argv[3];
    
    
    
    /* Create a TwitterOauth object with consumer/user tokens. */
    $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access, $secret);
    
    /* If method is set change API call made. Test is called by default. */
    $content = $connection->get('account/verify_credentials');
    
    /* Some example calls */
    $tw = $connection->post('direct_messages/new', array( 'screen_name' => $to, 'text' => $subject ) );
    
    
    /* Include HTML to display on the page */
    include('twitteroauth/html.inc');
  • efrain02
    Banned
    • Apr 2011
    • 81

    #2
    I'm trying this right now. But i have a question... on twitter there's a Consumer key and Consumer secret. And at the bottom of the page there's a Access token and Access token Secret. I want to know which of these do you use?
    Thanks.

    Comment

    • Javier
      Member
      Zabbix Certified Specialist
      • Jan 2010
      • 58

      #3
      In this blog, http://goo.gl/irTUU, in Spanish, it specifies how to send alerts to twitter in python code and using oauth.

      The sample code:
      Code:
      #!/usr/bin/python
      
      import sys
      import tweepy
      
      CONSUMER_KEY = 'xxxxxxxxx'
      CONSUMER_SECRET = 'yyyyyyyy'
      ACCESS_KEY = '000000000'
      ACCESS_SECRET = 'zzzzzzzzz'
      
      auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
      auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
      api = tweepy.API(auth)
      api.update_status(sys.argv[2])

      Comment

      • efrain02
        Banned
        • Apr 2011
        • 81

        #4
        Thankyou so much. Muchas gracias... en este momento lo reviso a ver que tal. Gracias de nuevo

        Comment

        Working...