Accepting facebook friend requests via email and cURL

I’m working on a system to be able to auto-accept certain friend requests. I will try migrating it to a mail rule asap and adding comment replies etcetera as part of a massive AI project I’m working on. Here’s my problem: the facebook accept request button does not return anything or accept the request when I curl the attached link as it should. What am i doing wrong?

Here is the code to get the link, feel free to poke it with a stick and improve it.


tell application "Mail"
	set theMessages to every message of message viewer 1
	set titles to subject of every message of message viewer 1
	set option to (choose from list titles)
	repeat with i from 1 to (the number of items in theMessages)
		if option as text is (item i of titles) as text then
			set thisMessage to item i of theMessages
			exit repeat
		end if
	end repeat
	set thisMessageSource to source of thisMessage as text
end tell

set thisMessageSource to removeEqualsRet(thisMessageSource)

set search1 to (offset of "Confirm friend request" in thisMessageSource) - 350

set clamp to (characters search1 through (search1 + 350) of thisMessageSource) as string

set search2 to (offset of "http://www.facebook.com" in clamp)

set clamp to (characters search2 through -1 of clamp) as string

set search3 to (offset of "\"" in clamp) - 1

set confirmLink to linkFix(characters 1 through search3 of clamp as string)

do shell script ("curl \"" & confirmLink & "\"")

return confirmLink


(* Here I add functions to turn mail's source garbage into a html link.*)


on removeEqualsRet(input)
	set output to ""
	repeat with i from 1 to (the number of paragraphs in input)
		try
			if character -1 of paragraph i of input is "=" then
				set output to output & characters 1 thru -2 of paragraph i of input as text
			else
				set output to output & paragraph i of input as text
			end if
		on error e
			set output to output & paragraph i of input as text
		end try
	end repeat
	return output
end removeEqualsRet

on linkFix(input)
	set output to ""
	repeat 20 times
		set amper to offset of "&" in input
		if amper is 0 then
			set input to output & input
			set output to ""
			exit repeat
		else
			set output to output & characters 1 thru amper of input as text
			set input to characters (amper + 5) thru -1 of input as text
		end if
	end repeat
	repeat 20 times
		set equi to offset of "=3D" in input
		if equi is 0 then
			set input to output & input
			exit repeat
		else
			set output to output & characters 1 thru equi of input as text
			set input to characters (equi + 3) thru -1 of input as text
		end if
	end repeat
	return input as text
end linkFix

I am fairly certain you cannot use CURL with Facebook. (They block it). Try a simply CURL request

curl -i “http://www.facebook.com/tiesto

And you will get:

I find a lot of people doing stuff like this to bypass the cURL restriction:

Source: http://www.kudanai.com/2008/09/changing-facebook-with-bash-curl-update.html

Additional sources (PHP based though)

http://codesnippets.joyent.com/posts/show/1204
http://www.questconsultantsllc.com/blog/curl-your-friend
http://www.daniweb.com/web-development/php/code/290893

Now I need to understand php enough to convert it to a bash or applescript script…

Figured out status updates:

property facebookUpdateAddy : "get this address from m.facebook.com/mobile and click email"
set status to "Your awesome status."
tell application "Mail"
	set theNewMessage to make new outgoing message with properties {subject:status, visible:false}
	tell theNewMessage
		make new to recipient at end of to recipients with properties {address:facebookUpdateAddy}
		send
	end tell
end tell

And also how to reply to wall posts/comments.


tell application "Mail"
	set theMessages to every message of message viewer 1
	set titles to subject of every message of message viewer 1
	set option to (choose from list titles)
	repeat with i from 1 to (the number of items in theMessages)
		if option as text is (item i of titles) as text then
			set thisMessage to item i of theMessages
			exit repeat
		end if
	end repeat
	set thisWallPost to (characters 2 thru -3 of (paragraph 4 of content of thisMessage)) as text
	
	set outAddy to reply to of thisMessage
	--set pos1 to offset of "<" in outAddy
	--set outAddy to characters (pos1 + 1) thru -2 of outAddy as text
	set theNewMessage to make new outgoing message with properties {subject:"Re: " & subject of thisMessage, visible:false}
	tell theNewMessage
		make new to recipient at end of to recipients with properties {address:outAddy}
		set content to "IT WORKS!"
		send
	end tell
	
end tell
activate