[Metalab] hack idea

Benjamin Klemencic benjamin at klemencic.org
Mon Feb 17 21:58:38 CET 2014


I've developed a bunch of apps on Facebook. 
This code here f.e. has been used as Armin Wolf asked his FB fans for TED talk recommendations. 
I've typed it within some minutes and I'm sure it is not optimized. 

-> Just let me know, what you need as an output. RSS, a Textfile, eMails?

FB also provides a technology called Realtime Update Subscriptions. So as soon as I know what we need I can simply hack something called Facebook App which one of the admins of the Metalab Facebook Page has to accept. That's it.

BR
Benjamin



<?php

require_once('facebook-php-sdk-master/src/facebook.php');
require_once('settings.php');
require_once('funcs.php');

echo '<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body><pre>';


function getTitle($Url){
    $str = file_get_contents($Url);
    if(strlen($str)>0){
        preg_match("/\<title\>(.*)\<\/title\>/",$str,$title);
        return $title[1];
    }
}

$postID = '723150577696814';

// CONNECT to FACEBOOK
try {
    $facebook = new Facebook(
        array(
            'appId'  => FB_APP_ID,
            'secret' => FB_SECRET,
        ));
} catch (FacebookApiException $e) {
    reportError('Cannot connect to Facebook'.var_export($e, true), __FILE__, __LINE__, 'FATAL ERROR');
    if (DEBUG_MODE){echo "ERROR 1".var_export($e);}
    exit;
}

$args = array(
    "access_token"  => FB_USER_ACCESS_TOKEN,
    "fields"        => 'message',
    "limit"         => '25',
    "after"         => '1',
);

$i=0;
$y=0;
while($args["after"]){
    try {
        $apiCall = "$postID/comments";
        $feed = $facebook->api($apiCall, 'GET', $args);
    } catch (FacebookApiException $e) {
        reportError("Facebook API error in $apiCall".var_export($e, true), __FILE__, __LINE__, 'FATAL ERROR');
        if (DEBUG_MODE){echo ' ...ERROR<br>'.var_export($e);}
    }

    foreach($feed["data"] as $comment){
        preg_match_all('#\bhttps?://[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/))#', $comment["message"], $match);

        foreach($match[0] as $url){
            //Example:
            echo getTitle($url)."<br>";
            echo $url."<br>"."<br>";
            $i++;
        }
    }

    if (isset($feed["paging"]["next"])){
        $args["after"] = $feed["paging"]["cursors"]["after"];
    }else{$args["after"] = false;}

    $y++;
}

// Youtube Data API

echo "<br>i=$i y=$y<br><i>END OF HTML</i></pre></body></html>";

?>

Am 17.02.2014 um 19:15 schrieb Michael Hauser:

> someone should set up a bot that auto pulls articles off facebook,
> whenever someone posts a link.
> 
> like, what phrik does on irc with the title of the page, if people post
> links.
> 
> i've had it with that childrenfucking farcefuck and am not gonna comment
> out fb's urls in my /etc/hosts, let alone visit this abomination again.
> 
> thanks for listening
> 
> mih
> 
> -- 
> 'aware water' is an anagram for 'we are at war'
> 
> _______________________________________________
> Metalab mailing list
> Metalab at lists.metalab.at
> https://lists.metalab.at/mailman/listinfo/metalab





More information about the Metalab mailing list