Comment

MakerTools

MakerTools is a simple project that I created for the Product Hunt community. In a nutshell, MakerTools will allow anyone who has had their product featured on Product Hunt to create a twitter list of all of their upvoters (they can then follow each person in just one click from Twitter, if they wish). You can find out more from my post on Medium.

It was written using the Slim PHP framework and Twig view files, with a pinch of Javascript. Both the Product Hunt and Twitter APIs were used to created this tool.

Click below to view the code used for the Twitter authorisation. I felt that it was important to show the makers who log in to MakerTools that even though it asks for Read and Write permissions, we will NOT tweet on their behalf or store any of their information (just incase anyone was hesitant to sign in).

Twitter Permission Usage

This code snippet shows all interactions with the Twitter API, I have added comments below to highlight each time the API is used in more detail.

<?php
.......
.......

$app->setName('Maker Tools');

use Abraham\TwitterOAuth\TwitterOAuth;

define('CONSUMER_KEY', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
define('CONSUMER_SECRET', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
define('OAUTH_CALLBACK', 'http://makertools.xyz/twitter.auth.callback.php?callback');

$client_id = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$client_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';


$app->get('/', function () use ($app) {
    .............
    .............
    //return list of all upvotes   
    if(!isset($_GET['action'])){
        $postid = $_GET['post_id'];
        $name = $_GET['name'];
        $thandles = json_encode($twitterHandles);
        $app->render('makeaction.twig', 
        array('title' => 'Select Action', 
            'postid' => $postid, 
            'name' => $name, 
            'thandles' => $thandles,
            'twitterhandles' => $twitterHandles
            ) 
        );
    }
            
    $tweeters = json_encode($twitterHandles);
                
    if(isset($action))
    {
        $action = $action;
        $ids = array();
        $names = array();
        $peoples = json_decode($tweeters);
        foreach($peoples as $people)
        {
            $ids[] = $people->id;
            $names[] = $people->name;
        }
        //LIVE
        $handles = $names;
                
        $connection = new TwitterOAuth(
            CONSUMER_KEY, 
            CONSUMER_SECRET,
            $access_token['oauth_token'],
            $access_token['oauth_token_secret']
        );
            
        if($action == 'list')
        {
            //Check list type
            $list_mode = $type;
            if($list_mode != 'public' && $list_mode != 'private'){
                $list_mode = 'public';
            }
            //Create new list
            $query = array('name' => 'Product Upvote List', 'mode' => $list_mode, 'description' => 'Upvoted '.$name.' on product hunt');
            $list = $connection->post('/lists/create', $query);        
            $slug = $list->slug;
            $owner = $list->user->screen_name;
                          
            //Total handles
            $total_handles = count($handles);
            $number_loop = ceil(($total_handles/100)); 
            
            //Check if more than 100 upvoters
            if($number_loop > 1){
                    
                for ($x = 0; $x < $number_loop; $x++) {

                    $offset = 100*(int)$x;
                    $use_array = array_slice($handles, $offset, 100, true);

                    //Update list
                    $query = array('screen_name' => implode(',',$use_array), 'slug' => $slug, 'owner_screen_name' => $owner); 
                    $listmem = $connection->post('lists/members/create_all', $query);

                } 
            }else{
                        
                //Can only use 100 at a time must add loop to make this work
                $query = array('screen_name' => implode(',',$handles), 'slug' => $slug, 'owner_screen_name' => $owner); 
                $listmem = $connection->post('lists/members/create_all', $query);
            }
                    
            $response = 'Your list has been created';
                    
        }
                
        $app->render('actioncomplete.twig', array('name' => $twittername, 'title' => 'Complete', 'response' => $response ) );
    }       
.........
.........
Google Analytics Alternative