MySpace bulletins to RSS

September 27th, 2007 by Aaron

Get MS hosting starting at less than $2 month + free domains.Click Here Now to Save.

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&amp;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 .= "&amp;password=" . urlencode($YOUR_PASSWORD);
$postfields .= '&amp;ctl00%24Main%24SplashDisplay%24login%24loginbutton.x=38&amp;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&amp;Mytoken=BA2B1E4D-950A-454A-BA25B1D55F6D1C1727874571">Skip this Advertisement &amp;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&amp;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.

Tags: ,


22 Responses to “MySpace bulletins to RSS”

  1. daviduxe Says:

    hey there. thanks a lot! have you made or post or could you explain to non-techies how to implement this?

  2. aaron Says:

    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!

  3. billynomates Says:

    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!

  4. aaron Says:

    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.

  5. billynomates Says:

    Ahh OK. Thanks very much.
    Yeah, I did notice it was commented out, I was just wondering.
    Cheers

  6. puneet ratan sharma Says:

    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

  7. aaron Says:

    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…

  8. puneet ratan sharma Says:

    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

  9. puneet ratan sharma Says:

    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

  10. aaron Says:

    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

  11. Lockjaw Says:

    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)

  12. aaron Says:

    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!

  13. wgato Says:

    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!

  14. Aaron Says:

    @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!

  15. Scott Crawford Says:

    Aaron,

    Getting the same error as wgato, and as I believe he’s a Dreamhost customer as I am because of the path structure, if I get a definitive answer on things, I’ll post it here so it can potentially help a few people out.

    Curiously, though, I’m also getting a 404 error on the linked “function.fopen” in the above error.

    Thoughts on this, and also on the minimum amount of permissions I should be CHMODing the file itself to would be greatly appreciated.

    -S

  16. Aaron Says:

    @Scott Crawford: Well, the 404 is based on whatever your PHP configuration says its base php manual URL should be. Generally, those HTML errors are not really worthwhile unless you’re using something like xdebug. AT any rate, when seeing those, you can either configure your php.ini help URL - or just put php.net/fopen into your address bar.

    As for the error that you guys are experiencing, I think it has to do with an incorrect path or a type-o. If you see, his error message gives it away.
    The real path is /home.magi/tr/tr.com….. where as his fopen path is /myspace/bulletins. SOO - what you need to do is make sure you get the full file system path in there… make sure the fopen starts with the full path:

    fopen(/home/.magi/tr/tr.com/myspace/bulletins.xml) would do the trick

  17. Scott Crawford Says:

    Aaron,

    I’ve tried posting the path a number of different ways (and making sure that the paths match in my cron job and my script, of course), but still no luck.

    I’ve tried /home/user/path/to/file, /home/.servername/user/path/to/file, and I even tried the shortened /path/to/file for the heck of it (though only in the script, as the cron job needs the full path).

    If I were to wager a guess, there’s a permissions issue somewhere that’s blocking the script from generating /myspace/bulletins.xml properly. I’ve tried CHMODing to 500, 550, and 551 so far, with no change in error message. Am I in the right ballpark permissions-wise?

    A final possibility is, of course, that something’s screwy server-side with simpleXML, but I haven’t heard anything that bears that out yet.

    Frustrating, because I feel like we’re close, and like it’s something totally dumb that’s in the way here.

  18. Aaron Says:

    @Scott Crawford: Try 664 after ‘touch bulletins.xml’ Should give the proper permissions…

  19. Scott Crawford Says:

    Aaron,

    Here’s where I’m at:

    The good: the “touch” command worked and created the bulletins.xml file. The perms are set to 664, so that’s all good. Not getting the script errors I was anymore, so we’re that much further along, finally.

    The bad: the bulletins.xml file doesn’t appear to be updating. No news items yet.

    The ugly: the script is generating files called “cookiejar-(string of numbers here)” in my home directory every time the cron job runs, which makes said directory a bit of a mess.

    Thoughts?

    Thanks again for your help,
    -S

  20. Aaron Says:

    @Scott Crawford: Well its been a while since I’ve actually revisited this script- and I don’t even use myspace anymore! :)
    1) the cookie jar one. Since you don’t have a working /tmp directory that you can access I’m sure, you may need to add an ‘unlink()’ statement at the end of the script to delete these files (all they are is the local ‘cache’ to accept cookies as you go from page to page.).
    2) the xml file not updating: hrm. Does it actually have content from the first run, but isn’t filling with new? or is there no content what so ever? You might want to try echo’ing out the contents to the console before you write the file to make sure it even has anything.

  21. Scott Crawford Says:

    I’m trying to free myself from the shackles of teh MySpace bulletins, and thankfully, a lot of my friends are either moving to Facebook or just giving up on social networks entirely, but in the meantime, this could be a super-helpful script, and thanks for investing the time you have into it.

    Onto the nitty gritty:

    1) Should I drop that ‘unlink()’ right after the fclose($fp); statement?

    2) XML file has its original attributes, but no news items in it yet. Being that I’m doing this with extremely limited *nix/terminal/command line knowledge, how would a brother go about echoing the script output? I had the cron results going to my email, but when the errors stopped, so did those emails.

    Thanks again for your time and patience through all of this.

  22. Aaron Says:

    @Scott Crawford: 1: yes. 2: try just printing $xml->asXML(). Instead of running it as cron, you should be able to extract your cron command and run it on the command line.
    Probably something like:

    php my_space_script.php

Leave a Reply

©2008 102 Degrees LLC - All Rights Reserved Home Services Products Network Blog Open Source Learning Contact