It is currently April 16th, 2024, 2:18 pm

thoughts on facebook

General topics related to Rainmeter.
User avatar
gschoppe
Developer
Posts: 93
Joined: April 26th, 2009, 8:30 pm
Location: St Johnsbury, VT

thoughts on facebook

Post by gschoppe »

ok, so facebook soesn't work with webparser due to their security (cookies/session authentication / ect) but I REALLY want my facebook feed on my desktop...

my thought for a solution:

build a cUrl based php shim website that takes standard POST arguments, scrapes facebook and returns an RSS feed... host this shim on a high bandwidth webhost (with php and curl)... and use webparser to access it.

I have, so far, completed 1 out of these tasks... here is a php function that, given an email and password, logs in to facebook and returns the facebook mobile feed...

Code: Select all

<?php
// Facebook Login cURL Shim
// author: gschoppe
// based on example script by:
// Jean-Baptiste Jung
// ---------------------------
// Login to Facebook Via PHP and cURL with POST arguments
// Set status, or return mobile homepage
// -------------------------------------
// EVENTUAL GOAL:
// full parsing for RSS feed

function fb_login ( $login_email = 'null', 
                    $login_pass  = 'null', 
                    $first_name  = 'null', //optional, necessary for setting status
                    $status      = 'null'  //optional, necessary for setting status
                  ) {

  if ( ($login_email == 'null') || ($login_pass == 'null') ){
    return 'login or pass not set';
  }
  
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, 'https://login.facebook.com/login.php?m&next=http%3A%2F%2Fm.facebook.com%2Fhome.php');
  curl_setopt($ch, CURLOPT_POSTFIELDS,'email='.urlencode($login_email).'&pass='.urlencode($login_pass).'&login=Login');
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch, CURLOPT_COOKIEJAR, "my_cookies.txt");
  curl_setopt($ch, CURLOPT_COOKIEFILE, "my_cookies.txt");
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
  curl_exec($ch);
  
  curl_setopt($ch, CURLOPT_POST, 0);
  curl_setopt($ch, CURLOPT_URL, 'http://m.facebook.com/home.php');
  $page = curl_exec($ch);
  
  if ( ($first_name == null) || ($status == null) ) {
    curl_setopt($ch, CURLOPT_URL, 'http://m.facebook.com/logout.php?r95ad1d04&refid=7');
    curl_exec($ch);
    curl_close($ch);
    
    //if ( $page == 0) {
    // return 'ERROR';
    //}
    
    return $page;
  }
  
  curl_setopt($ch, CURLOPT_POST, 1);
  preg_match('/name="post_form_id" value="(.*)" \/>'.ucfirst($first_name).'/', $page, $form_id);
  curl_setopt($ch, CURLOPT_POSTFIELDS,'post_form_id='.$form_id[1].'&status='.urlencode($status).'&update=Update');
  curl_setopt($ch, CURLOPT_URL, 'http://m.facebook.com/home.php');
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  
  $page = curl_exec($ch);
  
  curl_setopt($ch, CURLOPT_URL, 'http://m.facebook.com/logout.php?r95ad1d04&refid=7');
  curl_exec($ch);
  curl_close($ch);
  
  //if ( $page == 0) {
  //    return 'ERROR';
  //}
  return $page;

}
?>
if you anyone else knows php and regular expressions, I could use some help making this into an RSS feed...

also, if anyone has a high bandwidth host they'd like to donate space on, let me know.
Image
sgtevmckay

Re: thoughts on facebook

Post by sgtevmckay »

This is going to be a really stupid question :oops:

I presume you have gone over the following?
http://developers.facebook.com/
User avatar
gschoppe
Developer
Posts: 93
Joined: April 26th, 2009, 8:30 pm
Location: St Johnsbury, VT

Re: thoughts on facebook

Post by gschoppe »

unfortunately, screen-scraping is the only current way to get your feed, rather than just updates you yourself post, or that others have specifically made public... facebook claims this is a privacy concern, and thereby refuses to make an RSS/ATOM feed available, and purposefully cripples their api.
Image
sgtevmckay

Re: thoughts on facebook

Post by sgtevmckay »

Ouch :shock:
User avatar
gschoppe
Developer
Posts: 93
Joined: April 26th, 2009, 8:30 pm
Location: St Johnsbury, VT

Re: thoughts on facebook

Post by gschoppe »

so i've set up a live test @ http://www.gschoppe.com/fbtest.php?userName=EMAIL&pass=PASSWORD nothing is logged, and it works to retrieve the html, but does not parse to rss yet.

THIS TEST PAGE IS NOT PERMANENT, AND IF YOU USE IT TO MAKE A SKIN AND KILL MY BANDWIDTH LIMIT, I WILL HUNT YOU DOWN

however, it might help people to build regexps to parse the page, thus helping me reach my ultimate goal. BTW, if you are security conscious, please don't trust this link. Honestly, I could be doing ANYTHING in the php file. for those still willing to trust me a little, here is the php file running on the site, for your perusal:

Code: Select all

<?php
error_reporting (E_ALL ^ E_NOTICE);

@include('includes/fb_login.php');

if (!isset($_GET['userName']))
{
  //If not isset -> set with dummy value
  $_GET['userName'] = 'null';
}
if (!isset($_GET['pass']))
{
  //If not isset -> set with dummy value
  $_GET['pass'] = 'null';
}
if (!isset($_GET['firstName']))
{
  //If not isset -> set with dummy value
  $_GET['firstName'] = 'null';
}
if (!isset($_GET['status']))
{
  //If not isset -> set with dummy value
  $_GET['status'] = 'null';
}

$userName = $_GET['userName'];
$pass     = $_GET['pass'];
$first    = $_GET['firstName'];
$status   = $_GET['status'];  //100 char limit

//echo $userName;
//echo $pass;
//echo $first;
//echo $status;


echo fb_login($userName, $pass, $first, $status);

?>
Image
User avatar
gschoppe
Developer
Posts: 93
Joined: April 26th, 2009, 8:30 pm
Location: St Johnsbury, VT

Re: thoughts on facebook

Post by gschoppe »

i have updated the test page to provide a basic rss feed of recent status updates

Code: Select all

<?php
	$pregcrop = '/(?siU)" class="nopad">(.*)&nbsp;</';
	$preg = '/(?siU)<div id="anchor_fbid.*refid=7">(.*)<\/a> (.*)&nbsp;<small>(.*)<\/small>/';
	error_reporting (E_ALL ^ E_NOTICE);
	
	@include('includes/fb_login.php');
	
	if (!isset($_GET['userName']))
	{
	  //If not isset -> set with dummy value
	  $_GET['userName'] = 'null';
	}
	if (!isset($_GET['pass']))
	{
	  //If not isset -> set with dummy value
	  $_GET['pass'] = 'null';
	}
	if (!isset($_GET['firstName']))
	{
	  //If not isset -> set with dummy value
	  $_GET['firstName'] = 'null';
	}
	if (!isset($_GET['status']))
	{
	  //If not isset -> set with dummy value
	  $_GET['status'] = 'null';
	}
	
	$userName = $_GET['userName'];
	$pass     = $_GET['pass'];
	$first    = $_GET['firstName'];
	$status   = $_GET['status'];  //100 char limit
	
	//echo $userName;
	//echo $pass;
	//echo $first;
	//echo $status;
	
	
	$page = fb_login($userName, $pass, $first, $status);
	
	//echo $page . "\n\n\n";
	$out = 0;
	$mystatusarray = 0;
	
	preg_match($pregcrop, $page, $mystatusarray);
	$mystatus = $mystatusarray[1];
	$mystatustemp = explode (' ', $mystatus, 2);
	$mystatus = $mystatustemp[1];

	$pagesplit = preg_split($pregcrop, $page);
	
	preg_match_all($preg, $pagesplit[1], $out, PREG_PATTERN_ORDER);
	// $out[1] contains names, $out[2] contains messages, $out[3] contains times

	
	//print_r($mystatus);
	//echo"\n\n\n";
	//print_r($out);

	$max = min(count($out[1]), count($out[2]), count($out[3]));
?>

<rss version="0.91">
	<channel>
		<title><?=$name?>Unofficial Facebook.com Feed</title>
		<link>http://www.facebook.com/</link>
		<description>Status update feed for Facebook.com</description>
		
		<item>
			<title>My Current Status</title>
			<link>http://www.facebook.com</link>
			<description><?=$mystatus?></description>
		</item>
<?php
	for ($i=0;$i<$max;$i++)
	{
?>
		
		<item>
			<title><?=$out[1][$i]?> - <?=$out[3][$i]?></title>
			<link>http://www.facebook.com</link>
			<description><?=$out[2][$i]?></description>
		</item>
<?php
	}
?>
		
	</channel>
</rss>
Image
User avatar
gschoppe
Developer
Posts: 93
Joined: April 26th, 2009, 8:30 pm
Location: St Johnsbury, VT

Re: thoughts on facebook

Post by gschoppe »

Image
sgtevmckay

Re: thoughts on facebook

Post by sgtevmckay »

ant or none of this may be relevent.
As I have an account...I have not accessed in many months...I am immediately unsure.
http://www.readwriteweb.com/archives/facebook_announces_roadmap_for_developers.php