MySpace bulletins to RSS
September 27th, 2007 by Aaron
So I’m sick of myspace… or so I say to myself. So now I log in about half the time as I did before… and this is because I’ve made the following script. It logs in and grabs each bulletin from your top bulletins. Then, it creates an RSS feed from them.
Lets check it out:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | <?php set_time_limit(0); $ch = curl_init(); // // setup and configure // $randnum = rand(1,9999999); curl_setopt($ch, CURLOPT_COOKIEJAR, "cookiejar-$randnum"); curl_setopt($ch, CURLOPT_COOKIEFILE, "cookiejar-$randnum"); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1"); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 0); // // get homepage for login page token // curl_setopt($ch, CURLOPT_URL,"http://www.myspace.com"); $page = curl_exec($ch); // // find it.... // preg_match("/MyToken=([^\"]+)\"/",$page,$token); $token = $token[1]; // // do login // $YOUR_EMAIL = 'e@mail.com'; $YOUR_PASSWORD = 'yourpassword'; curl_setopt($ch, CURLOPT_URL,"http://login.myspace.com/index.cfm?fuseaction=login.process&MyToken={$token}"); curl_setopt($ch, CURLOPT_REFERER, "http://www.myspace.com"); curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: application/x-www-form-urlencoded")); curl_setopt($ch, CURLOPT_POST, 1); $postfields = "email=" . urlencode($YOUR_EMAIL); $postfields .= "&password=" . urlencode($YOUR_PASSWORD); $postfields .= '&ctl00%24Main%24SplashDisplay%24login%24loginbutton.x=38&ctl00%24Main%24SplashDisplay%24login%24loginbutton.y=15'; curl_setopt($ch, CURLOPT_POSTFIELDS,$postfields); $page = curl_exec($ch); //check for skip this advertisement // //<a href="http://home.myspace.com/index.cfm?fuseaction=user&Mytoken=BA2B1E4D-950A-454A-BA25B1D55F6D1C1727874571">Skip this Advertisement &raquo;</a> preg_match("/<a href=\"(.*?)\">Skip this Advertisement/", $page, $redirpage); if (isset($redirpage[1])) { curl_setopt($ch, CURLOPT_REFERER,"http://login.myspace.com/index.cfm?fuseaction=login.process&MyToken={$token}"); curl_setopt($ch, CURLOPT_URL,$redirpage[1]); curl_setopt($ch, CURLOPT_POST, 0); $page = curl_exec($ch); } // // check login error // if(strpos($page,"You Must Be Logged-In to do That!") !== false){ // login error print 'login error'; return 2; } // // LOGGED IN, now let's play // // find edit profile link (with token attached) // //preg_match("/ id=\"ctl00_Main_ctl00_Welcome1_EditMyProfileHyperLink\" href=\"([^\"]+)\"/",$page,$redirpage); //$redirpage = $redirpage[1]; // // go there (edit profile) // //curl_setopt($ch, CURLOPT_URL, $redirpage); //$page = curl_exec($ch); // //echo $page; // do whatever you need to do // // clean up // //curl_close($ch); @unlink("/tmp/cookiejar-$randnum"); //comment this //$page = file_get_contents('src.txt'); preg_match('/<h5 class="heading">\s+My Bulletin Space\s+<\/h5>\s+<div style="padding:2px;">(.*?)(<tr>(.*?)<\/tr>\s+)<\/table>(.*?)<\/div>/s', $page, $found); // cuz i suck preg_match_all('/<tr>(.*?)<\/tr>/s', $found[2], $tds); array_shift($tds[0]); $rss = new simpleXMLElement('<rss version="2.0"></rss>'); $channel = $rss->addChild('channel'); $channel->addChild('title', "Bulletins for Myspace"); $channel->addChild('description', 'RSS feed for MySpace bulletins'); $channel->addChild('language', 'en-us'); $channel->addChild('pubDate', date('r')); $channel->addChild('lastBuildDate', date('r')); sleep(2); foreach ($tds[0] as $td) { sleep(1); preg_match('/href=\'(.*?)\'/', $td, $match); //$match[1] is the url curl_setopt($ch, CURLOPT_URL,$match[1]); curl_setopt($ch, CURLOPT_POST, 0); $page = curl_exec($ch); preg_match('/<table id="betterb">(.*?)<\/table>/s', $page, $bul); array_shift($bul); $bul = preg_replace('/<\/?t[r|d|h].*?>/', '', $bul[0]); //build subject preg_match("/Subject:(.*?)Body/s", $bul, $titlematch); $title= trim(htmlentities(strip_tags($titlematch[1]))); //build title preg_match("/Date:(.*?)Subject/s", $bul, $datematch); $predate= htmlentities(strip_tags($datematch[1])); $pubdate = date('r', strtotime($predate)); $item = $channel->addChild('item'); $bul = trim($bul); $bul = html_entity_decode($bul); $bul = html_entity_decode($bul); $bul = htmlentities($bul); $item->addChild('title', "Bulletin from: " . $title); $item->addChild('description', $bul); $item->addChild('pubDate', $pubDate); } $fp = fopen('/yourhosthere/myspace/bulletins.xml', 'w'); fputs($fp, $rss->asXML()); fclose($fp); |
This code was heavily inspired from another blog posting - but I can’t seem to remember their page anymore
I’m still having an issue with google reader saying that some of the bulletins are new when they’re not. I’m not sure if it is something in my script yet or if its something on the bulletins themselves…
any input would be appreciated.
This entry was posted on Thursday, September 27th, 2007 at 10:00 am and is filed under PHP. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.















December 20th, 2007 at 5:34 pm
hey there. thanks a lot! have you made or post or could you explain to non-techies how to implement this?
January 3rd, 2008 at 6:45 pm
Hello,
Thanks for your interest. I’m sorry, but I haven’t written a non-technical implementation of this. If I get around to it, I’ll make sure to ping ya. Thanks!
January 16th, 2008 at 11:43 am
So, just a few questions.
I upload this to my server space, change the details where it says username and password, and where it says ‘your host here’, then add the url to this script to Google reader, is that right?
Also, why does it need to go onto the edit profile page?
Thanks in advance!
January 16th, 2008 at 10:25 pm
You don’t add the URL of the script, you add the URL of the xml file it creates. Then, the script needs to be scheduled to be ran - such as by cron using PHP command line.
The edit profile page is commented out. Its there as a code example so you “could” update the profile if you wanted to. Right now, it doesn’t do it.
January 17th, 2008 at 8:24 am
Ahh OK. Thanks very much.
Yeah, I did notice it was commented out, I was just wondering.
Cheers
March 17th, 2008 at 2:13 pm
Hello Team,
You really done a great job, i used to ur code to connect my site to myspace, But when i m using ur code, i got some error at myspace screens .which are given below :=
“Sorry! an unexpected error has occurred.
This error has been forwarded to MySpace’s technical group. ”
can you plz help me out to remove this solution,
what i did upto today, i can tell u here in the following steps
1:= Create a login page
then submit the page
2:= Now i want to upload some pics and create child also
which is in ur code but u did not give the function simpleXMLElement()
and tell me wht is the use of this function.
I m eagerly waiting of ur response.
plz mail asap.
Thanks
Puneet
March 17th, 2008 at 7:50 pm
Hello - thanks for your comment.
Well, first of all, when you have that error you specified, its usually something to do with the internals of myspace and not necessarily related to the script that is written. I would verify that you are sending the ‘mytoken’ with every request, however.
I don’t fully understand the next question… If you’re wondering what simpleXMLElement is doing, search the string on php.net. Basically it just creates an XML item as an object. Once you start adding items to the object, a hierarchy is created. Then, you can generate well formed XML from the object.
I hope that helps…
March 18th, 2008 at 2:38 pm
hello aaron ,
thanks for responding,
i got that simpleXMLElement() is a inbuilt function of php, but as per ur code, we got the blank .
My requirment is that (sorry that i m disturbing u again and again)
that i have to make the login on my site, and after login, i can create child on myspace thru our site..
is ur code can do this.
Thanks
Puneet
March 18th, 2008 at 2:45 pm
one more thing aaron,
how do i check, that i have logged in on myspace.
Like Facebook (in facebook we get the session id of the user) is something like happened in myspace also?
Thanks
Puneet
March 18th, 2008 at 6:03 pm
I wonder if your homepage hasn’t been changed to the ‘new style’. This was for the old version of the homepage… that might be the issue.
In order to determine that you’re logged in, you can search for items like ‘logged in’ or something else. I’ve never actually had that issue so I’ve never looked.
Good luck!
-aaron
April 14th, 2008 at 11:09 am
dear aaron
you script seems to be exactly what i need for my page. since i´m totally unsuspecting php and stuff i don´t know what to do with the text (script) above. i copied it to the windows editor, saved it as .php and uploadet it into my webspaces script dir. then i changed “e-mail” and “passwort”. if i run the script in opera nothing happens. in explorer it says:
Fatal error: Cannot instantiate non-existent class: simplexmlelement in /WWWROOT/54542/htdocs/scripte/feed.php on line 90
I know this is because i´m stupid. but it would be cool if you could help me (and probably others) out whit giving a short “how-to”.
all the best,
lockjaw
(germany)
April 14th, 2008 at 8:33 pm
Hey - make sure that your PHP instance supports SimpleXML.
Run these examples from the PHP manual on your install:
http://us2.php.net/manual/en/function.simplexml-element-construct.php
If that fails, then you know its an issue - and you need to upgrade or enable the simpleXML feature. Good luck!
May 11th, 2008 at 7:58 pm
Hi-
I’m struggling a bit trying to get this working. I confirm that my server is using PHP version 5, uploaded the script but I get the error:
Warning: fopen(/myspace/bulletins.xml) [function.fopen]: failed to open stream: No such file or directory in /home/.magi/tr/tr.com/myspace/msrss.php on line 115
Warning: fputs(): supplied argument is not a valid stream resource in /home/.magi/tr/tr.com/myspace/msrss.php on line 116
Warning: fclose(): supplied argument is not a valid stream resource in /home/.magi/tr/tr.com/myspace/msrss.php on line 117
I tried creating a /myspace folder but no luck. Any suggestions?
thanks!
May 11th, 2008 at 8:01 pm
@wgato: It could be that the script can’t recognize the location of ‘/myspace/bulletins.xml’ - especailly if you’re running it out of your tr.com folder.
I would try replacing that fopen command with ‘/tr.com/myspace/bulletins.xml’ or even ‘/home/.magi/tr/tr.com/myspace/bulletins.xml
good luck!