NAME
WWW::MySpaceBot - A libwww-perl interface to MySpace.
SYNOPSIS
use WWW::MySpaceBot;
my $myspace = new WWW::MySpaceBot;
# Sign In
$myspace->login (
email => 'myname@yourdomain.com',
password => 'big_secret_password',
) or die "Login Failed!";
# Print some details
print "My Friend ID: " . $myspace->myFriendID . "\n";
print "My Username: " . $myspace->myUsername . "\n";
# Check for new friend requests.
if ($myspace->newFriendRequests) {
my $requests = $myspace->friendRequests;
# Approve each of them.
foreach my $FriendID (keys %{$requests}) {
print "Approving Friend: $requests->{$FriendID}\n";
$myspace->approveFriend ($FriendID);
}
}
DESCRIPTION
WWW::MySpaceBot is a Perl MySpace interface that uses libwww-perl, and is therefore more portable without requiring any non-standard Perl modules.
CORE METHODS
new (%ARGS)
Create a new WWW::MySpaceBot object. You can pass in default variables here:
debug => Debug Mode
dumper => To dump HTML pages into files (for debugging)
agent => A User-Agent string to use
username => Your MySpace username
password => Your MySpace password
cookies => Path to a cookie jar
autoscan => (0|1) Automatically scan the Homepage for new messages on login
makeAgent
Creates a new LWP::UserAgent.
debug ($MESSAGE)
Prints a debug string.
dump ($FILENAME, $CONTENT)
Dumps HTML content to a file (for debugging).
request (METHOD, URL[, FIELDS])
Sends an HTTP request to URL using method METHOD. If METHOD is 'POST', then FIELDS should be the form fields to send in.
AUTHENTICATION AND HOMEPAGE METHODS
login ($USERNAME, $PASSWORD), login (%DETAILS)
Log in to MySpace. You can pass in $USERNAME and $PASSWORD in array form, or as a hash. For the hash, the keys username (or email) and password are used.
Returns true on successful connect.
isLoggedIn
Returns true if you are logged in.
myAccountName
Returns your account name (e-mail address you signed in with).
myPassword
Returns the password you provided at login.
myFriendID
Returns your Friend ID.
myNickname, myUsername
Returns your username.
scanHomepage ($URL[, $CONTENT])
Scans the homepage to find your username, FriendID, and to check for new messages, comments, picture comments, friend requests, and other notifications.
NOTIFICATION METHODS
newMessages
Returns 1 or 0 indicating if you have a "New Messages!" notification.
newFriendRequests
Indicates if you have "New Friend Requests!"
newComments
Indicates if you have "New Comments!"
newPictureComments
Indicates if you have "New Picture Comments!"
newBlogComments
Indicates if you have "New Blog Comments!"
newBlogs
Indicates if you have "New Blog Subscription Posts!"
newEvents
Indicates if you have "New Event Invitations"
newBirthdays
Indicates if you have "New Birthdays!"
newStudents
Indicates if your school has "NEW Students!"
FRIEND REQUEST METHODS
friendRequests
Checks for new friend requests. Returns a hashref of Friend IDs (keys) and Usernames (values). Also internally stores GUIDs for each Friend Request.
approveFriend ($FriendID)
Approves a pending friend request. You must call friendRequests
first so that you can get their GUID. Returns true on success.
denyFriend ($FriendID)
Deny a friend request. Returns true on success.
FRIENDS LIST METHODS
getFriends ($FriendID[, $PAGE])
Gets the list of friends for $FriendID. $PAGE is optionally a specific page to get (defaults to 1).
Returns Friends in an arrayref of hashrefs, in the order they appeared on the page. The keys of each hashref are:
FriendID => Their FriendID
Username => Their Username
getFriendsPages ($FriendID)
Gets the number of pages on $FriendID
's Friends Pages. If you call this after at least one getFriends()
call, it will be able to return the number instantly. Else it will need to call getFriends()
for itself to find out.
COMMENT METHODS
getComments ($FriendID[, $PAGE])
Returns the comments that $FriendID has. Returns an arrayref of hashrefs. The hashref keys are as follows:
FriendID => Their FriendID
Username => Their Username
Date => Timestamp of the comment
Message => The comment's body
postComment (%ARGS)
Post a comment on somebody's MySpace. %ARGS
is a hash:
FriendID => The target's FriendID
Message => A comment to put on their MySpace
Body => An alternative to Message
commentFriends ($MESSAGE)
Posts $MESSAGE
as a comment to all of your friends.
PROFILE METHODS
scanProfile ($FriendID)
Scans $FriendID
's profile page to find information retrievable in the following methods.
friendInfo ($TYPE, $FriendID[, $FORCE])
Retrieves a bit of information $TYPE
about $FriendID
. $TYPE
would be any of the following:
Username Headline Profile
Gender Age State
Country
This method will call scanProfile
if need-be. If $FORCE
is true, it will force a re-grab of their profile page.
friendUsername ($FriendID[, $FORCE])
friendHeadline ($FriendID[, $FORCE])
friendAddress ($FriendID[, $FORCE])
friendGender ($FriendID[, $FORCE])
friendAge ($FriendID[, $FORCE])
friendLocation ($FriendID[, $FORCE])
friendCountry ($FriendID[, $FORCE])
Retrieves one piece of information about $FriendID
, to get their username, headline, profile address, gender, age, state, and country respectively.
friendDetails ($FriendID)
Returns the details about $FriendID, as found in the "Details:" box in their profile. Returns a hashref with the following keys:
Status => Their marital status
'Here for' => What they're on MySpace for
Orientation => Their sexual orientation
Hometown => Their hometown
'Body type' => Their body type
Ethnicity => Their race
Religion => Their religion
'Zodiac Sign' => Their star sign
'Smoke / Drink' => Self-explanatory
Children => If they have children
Education => Their education level
Values will be 'undefined' if the user hasn't specified them.
BULLETIN METHODS
getBulletins ([$PAGE])
Gets all the current bulletins for $PAGE (which defaults to 1). Returns an arrayref of hashrefs. The arrayref is in the same order as the bulletins appeared on the page (newest is first). The hashrefs contain the details of the bulletin:
FriendID => The poster's ID
Username => The poster's username
Date => The timestamp of the bulletin
BulletinID => The bulletin's ID
Subject => The bulletin's subject
readBulletin ($BulletinID)
Reads the bulletin $BulletinID
. Returns a hashref:
FriendID => The poster's ID
Username => The poster's username
Date => The timestamp of the bulletin
Subject => The bulletin's subject
Message => The body of the bulletin
postBulletin (%FIELDS)
Post a new bulletin. Returns true on success. Pass arguments in hash form:
Subject => The bulletin's subject
Message => The bulletin's message
Body => An alternative to Message
deleteBulletin ($BulletinID)
Delete one of your bulletins. Returns true on success.
KNOWN ISSUES
The module runs kind of slowly. LWP::UserAgent was created to use LWP::ConnCache to speed up requests. If anybody has any suggestions to increase speed, please let me know!
The commentFriends() method is kind of buggy.
CHANGES
Version 0.01
- Initial release.
AUTHOR
Cerone Kirsle, administrator -at- kirsle.com
LICENSE
Released under the same terms as Perl itself.