Results 1 to 4 of 4

Thread: Last.fm "Add to mySpace" - how?!

  1. #1

    Last.fm "Add to mySpace" - how?!

    Hey Guys,

    I've ben racking my head trying work work out how the bright spark at last.fm achieved the 'add to my myspace' function to their widgets!

    Does anyone have any ideas?

    I found the following PHP class: http://www.weberdev.com/get_example-4510.html - but the scripts old which is why I assume it doesn't work, and my attempts to contact the dev have been unsuccessful!

    Appreciate anyones input

    Zaid

  2. #2
    have you tried posting on Last.fm's forums ? or contacting the php guys through their profile pages ?

  3. #3
    Quote Originally Posted by mlk View Post
    have you tried posting on Last.fm's forums ? or contacting the php guys through their profile pages ?
    Thanks for the reply!

    Im not that familiar with their community - but I'll certainly try it now!

    After trawling the web I pieced this together - it works, but its slow and pretty hit and miss.

    Would any be interested In collaborating on this?
    Last edited by Zaid_W1red; February 6th, 2008 at 11:32 PM.

  4. #4
    PHP Code:
    <?php
    function extractText($pat1,$pat2,$page) {
            
    $result null;
            
    //We explode the initial HTML
            
    $result = @explode($pat1$page);
            
    //then we explode the "right" part of the html
            
    $result = @explode($pat2$result[1]);
            
    //We get the "middle" part, whatever was between $pat1 and $pat2
            
    $result $result[0];
            
    //We need to take out any line breaks
            
    $result ereg_replace("<br>"""$result);
            
    //take out any whitespace
            
    $result trim($result);
            return 
    $result;
        }

    $email "";
    $password "";
    $content ""

    $ch curl_init();
    $randnum rand(1,9999999);
    curl_setopt($chCURLOPT_COOKIEJAR"/tmp/cookiejar-$randnum");
    curl_setopt($chCURLOPT_COOKIEFILE"/tmp/cookiejar-$randnum");
    curl_setopt($chCURLOPT_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($chCURLOPT_FOLLOWLOCATION1);
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
    curl_setopt($chCURLOPT_POST0);
    curl_setopt($chCURLOPT_URL,"http://www.myspace.com");
    $page=curl_exec($ch) ;
    // find  the token
    //
    preg_match("/amp;MyToken=([^\"]+)\"/",$page,$token);
    $token $token[1];
    //We have the token, log into MySpace.
    //
    // do login
    //
    curl_setopt($chCURLOPT_URL,"http://login.myspace.com/index.cfm?fuseaction=login.process&MyToken={$token}");
    curl_setopt($chCURLOPT_REFERER"http://www.myspace.com");
    curl_setopt($chCURLOPT_HTTPHEADER, Array("Content-Type: application/x-www-form-urlencoded"));
    curl_setopt($chCURLOPT_POST1);
    $postfields "email=" urlencode($email);
    $postfields .= "&password=" urlencode($password);
    $postfields .= '&ctl00%24Main%24SplashDisplay%24login%24loginbutton.x=38&ctl00%24Main%24SplashDisplay%24login%24loginbutton.y=15';
    curl_setopt($chCURLOPT_POSTFIELDS,$postfields);
    $page curl_exec($ch);
    preg_match("/fuseaction=user&Mytoken=(.*)\"/",$page,$token);
    $redirpage="http://home.myspace.com/index.cfm?fuseaction=user&MyToken=$token";
    // do the redirect to user home page
    curl_setopt($chCURLOPT_REFERER,"http://login.myspace.com/index.cfm?fuseaction=login.process&MyToken={$token}");
    curl_setopt($chCURLOPT_URL,$redirpage);
    curl_setopt($chCURLOPT_POST0);
    $page curl_exec($ch) ;
    echo 
    "loged in...";

    //Once logged in, goto the edit profile page and post
    // edit profile page
    preg_match("/profile.interests&MyToken=(.*)\"/",$page,$token);
    $token $token[1];

    curl_setopt($chCURLOPT_URL,"http://www.myspace.com/index.cfm?fuseaction=profile.interests&MyToken=MyToken={$token}");
    curl_setopt($chCURLOPT_REFERER"http://www.myspace.com");
    curl_setopt($chCURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded"));
    curl_setopt($chCURLOPT_POST1);

    $page curl_exec($ch);

    $hash extractText('ctl00_ctl00_cpMain_ProfileEditContent_editInterests_hash" value="','"',$page);
    $viewstate extractText('__VIEWSTATE" value="','"',$page);
    $currenttext extractText('<textarea name="ctl00$ctl00$cpMain$ProfileEditContent$editInterests$AboutMeTextBox" rows="15" cols="20" id="ctl00_ctl00_cpMain_ProfileEditContent_editInterests_AboutMeTextBox" class="w500">','</text>',$page);
    $currenttext explode("</textarea>",$currenttext);


    echo 
    "About Box -->".$currenttext[0];

    echo 
    "<br/>Prefetched hash--> ".$hash."<br/>";
    echo 
    "<br/>Prefetched viewstate--> ".$viewstate."<br/>";
    curl_setopt($chCURLOPT_URL,"http://www.myspace.com/index.cfm?fuseaction=profile.interests&MyToken=MyToken={$token}");
    curl_setopt($chCURLOPT_REFERER"http://www.myspace.com");
    curl_setopt($chCURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded"));
    curl_setopt($chCURLOPT_POST1);
    $postfields "&__VIEWSTATE=$viewstate";

    $postfields .= "&ctl00%24ctl00%24cpMain%24ProfileEditContent%24editInterests%24hash=$hash";

    $postfields .= "&ctl00%24ctl00%24cpMain%24ProfileEditContent%24editInterests%24SaveInterests=Save All Changes";

    //$postfields .= "&ctl00%24ctl00%24cpMain%24ProfileEditContent%24editInterests%24LikeToMeetText=your mum";

    $postfields .= "&ctl00%24ctl00%24cpMain%24ProfileEditContent%24editInterests%24AboutMeTextBox=".$currenttext[0]."$content";

    curl_setopt($chCURLOPT_POSTFIELDS,$postfields);
    $page curl_exec($ch);


    if(
    preg_match("/Profile Updated/",$page)){
    echo 
    "done<br/><br/>";
    exit;
    }else{

    echo 
    "nope!";
    }

    curl_setopt($chCURLOPT_REFERER,"http://collect.myspace.com/index.cfm?fuseaction=signout");
    curl_setopt($chCURLOPT_URL,$redirpage);
    curl_setopt($chCURLOPT_POST0);
    $page curl_exec($ch) ;

    print 
    $page;
    ?>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012