MySpace Open Platform

A Place For Developers

Welcome Developers!

in

Welcome!

in

Example: PHP show friends page

Last post 03-10-2009 8:12 PM by Mehedi Hasan. 13 replies.
Page 1 of 1 (14 items)
Sort Posts: Previous Next
  • 02-27-2008 11:14 AM

    • Daniel
    • Not Ranked
    • Joined on 02-06-2008
    • Posts 1

    Example: PHP show friends page

    So this is for all the Newbie out there.

    I’m a Facebook app developer and only today I success on building my first PHP Open Social app.

    I will share it with you so all the newbies will get a good start and the experts can comment my way and help me improve my knowledge on MySpace Open Social.

     

    This example set an Iframe on the canvas, get the user ID using JS and load PHP page with the user ID (as parameter). In the PHP page I use the PHP Client Library (http://developer.myspace.com/Community/forums/t/157.aspx) to show the user parameters and his friends.

    App Source:

    <iframe id="frame" width="800" height="500" frameborder="0"></iframe>

    <BR>

    <div id='message' style='margin: 4px'></div>

    <script type='text/javascript'>

    function init() {

      MYOS_TRACE = true; 

      var os = opensocial.Container.get();

      var dataReqObj = os.newDataRequest();

     

      var viewerReq = os.newFetchPersonRequest(opensocial.DataRequest.PersonId.VIEWER);

      dataReqObj.add(viewerReq);

     

    dataReqObj.send(dataLoadCallback);

    }  

     

    function dataLoadCallback(dataResponse) {

     

      if (dataResponse.hadError()) {

        alert(“Error”);

      } else {

        var viewerData = dataResponse.get(opensocial.DataRequest.PersonId.VIEWER).getData();

        var viewerName = viewerData.getField(opensocial.Person.Field.ID);

        document.getElementById('frame').src = "http://XXXXXXX/file.php?id="+ viewerName;

     
      }

    }

     
    init();

    </script>

     The PHP page:

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    <body>
    <?php
        $user = $_GET["id"];
      require_once('Space.php');
      $key = 'XXXXXXXXXXXXXXXXXXXXXXXX';
      $secret = 'XXXXXXXXXXXXXXXXXXXXXXXXX';
      $s = new Space($key,$secret);
      $hProfile = $s->profile($user);
      foreach($hProfile as $k => $value){
          echo "<BR><strong>".$k."</strong>:".$value;
      }
      echo "<hr>Friend list";
      $hFriends = $s->friends($user);
      foreach($hFriends["friends"] as $friend){
          echo "<BR><u>Frend</u>";
        foreach($friend as $k => $value){
            echo "<BR><strong>".$k."</strong>:".$value;
        }
      }
    ?>
    </body>
    </html>


    I’m not secure if Iframe is the best way and hopping to get comments from others.

     

    Regards,

    Daniel

    Filed under: , ,
  • 03-13-2008 1:35 PM In reply to

    • J9
    • Top 50 Contributor
    • Joined on 02-13-2008
    • Posts 89
    • MDP Team

    Re: Example: PHP show friends page

    Thanks for sharing!

  • 03-13-2008 8:17 PM In reply to

    Re: Example: PHP show friends page

     This only shows the first 20 friends. How do I show all the friends?

  • 03-14-2008 10:21 AM In reply to

    Re: Example: PHP show friends page

    What about the security risk of passing in a user id which can be passed in by anyone.  Do you do any kind of checking to verify that?
  • 03-14-2008 3:55 PM In reply to

    Re: Example: PHP show friends page

    I don't know much about the internal workings of the PHP Client Library, but I think, as of right now, you can only grab 20 friends at a time with it. I imagine at some point someone will fix that and put the fixed version up.

    And to the second question -- because the Ids are included in the basestring when the Signature is created, for someone to change them, they'd have to be able to produce a valid oauth_signature with the new values. To do that they'd need your App's security key.

  • 03-26-2008 9:58 AM In reply to

    Re: Example: PHP show friends page

      Regarding the 20 friend limit, i seem to recall messing around with this a little while back.  All u need is a couple more parameters when calling the friends function..

    Instead of.. 

    $hFriends = $s->friends($user);

    use(where $friend_limit is your max number of friends u want returned)..

    $hFriends = $s->friends($user,NULL,$friend_limit);

    i seem to remember there was a bug in the space.php that i had to change to get this to work.. i dont know if the client library has been corrected yet or which bit i had to change, so ill copy the whole friends function...

    public function friends($iUser,$page = null,$page_size = null,$list = null) {
        $sQuery = 'users/'.$iUser.'/friends';
        $hParams = array();
        if( $page !== null ) {
          $hParams['page'] = $page;
        }

        if( $page_size !== null ) {
          $hParams['page_size'] = $page_size;
        }

        if( $list !== null ) {
          $hParams['list'] = $list;
        }
        return $this->do_request($sQuery,$hParams);
      }

     

    hope this helps,

    Paul 

  • 03-27-2008 11:51 AM In reply to

    Re: Example: PHP show friends page

    Daniel:

    function dataLoadCallback(dataResponse) {

     

      if (dataResponse.hadError()) {

        alert(“Error”);

      } else {

        var viewerData = dataResponse.get(opensocial.DataRequest.PersonId.VIEWER).getData();

        var viewerName = viewerData.getField(opensocial.Person.Field.ID);

        document.getElementById('frame').src = "http://XXXXXXX/file.php?id="+ viewerName;

     
      }

    }

     

     

    Daniel,

    Thanks for the share agaiain , but I'm facing problem with this everytime I paste this code on my Canvas source it Either shows error as follows:

    1.Your source contains errors. Please correct and try again.

    Type Message Line Column
    INVALID_IDENTIFIER
    -1 -1

     

    Or 2. Just Iframe tag is shown on the canvas page of the application.

     

    Formerly, as far as I knw, It'd worked once for me:

    my Application is ready at :

    http://www.unique-group.org/MYSPACEAPPS/NICKNAMES/

    There in application,I've provided the user_id param manually, but now what I want to do is pass user_id as something like  /index.php?user_id=viewer_id .But it is not getting.I'm stuck here.Please help me with.

    thx, 

  • 03-29-2008 7:09 PM In reply to

    Re: Example: PHP show friends page

    Jeremy:

    And to the second question -- because the Ids are included in the basestring when the Signature is created, for someone to change them, they'd have to be able to produce a valid oauth_signature with the new values. To do that they'd need your App's security key.

    I think he meant this line:

     document.getElementById('frame').src = "http://XXXXXXX/file.php?id="+ viewerName;

    What's to stop someone going to eg. file.php?id=[some user with a private profile that has the app installed] to view a private user's friends list? Or is there something I'm missing, some checking done?

  • 03-30-2008 2:46 AM In reply to

    Re: Example: PHP show friends page

    Whoops. That's what I get for not actually reading through the code.

    In that case you're absolutely right - no checking is done. That code is nice, but to be honest, it's not the best way to handle this situation. Two alternatives would be use an External IFrame-type canvas, which does the appending automatically (and does it at the relay, where it's signed, so there's no way to fake an Id) or to use an HTML-response makeRequest instead of an IFrame. The PHP file will return an HTML page, and you'd just dump that response into the innerHTML of a div. If you sign the makeRequest, it'll have the owner and viewer ids appended automatically - you can't hack them in through the javascript. To prevent a spoof to your sever, you can also sign the request and check OAuth at your end.

    The method above, like I said, is workable, but it doesn't implement any security features. Sorry about saying that.

  • 01-02-2009 3:58 AM In reply to

    Re: Example: PHP show friends page

     finally!

     

    Thanks, you get one of the two spots in my big credit thanks! you're awesome!!!

  • 01-04-2009 1:34 PM In reply to

    Re: Example: PHP show friends page

    App Source worked, now it doesn't. What did I do... ??

    I had the MySpace App source listed here, with the JavaScript working. now it seems I can't get something as simple as a js Alert(); function to display consistantly. It does seem it will work Off and On, but I don't know what I'm doing at this point. 

    Here's what I'm doing, from this page http://developer.myspace.com/Apps.mvc, I click "Edit Source." Under the "Canvas Surface" I put in something as simple as,

     <script language="javascript" type="text/javascript">
    alert('This is what an alert message looks like.');</script> 

    Click the "Save Application Souce" and click the "View Development Version" but no luck! I see no alert. If I do something as simple as an <iframe src=""> to pull up an external page it works fine. What am I doing wrong here?? Your help would be greatly appreciated.
  • 01-08-2009 1:41 PM In reply to

    Re: Example: PHP show friends page

    The alert function is blocked, try outputting something to a div, e.g.:

    <div id="output"></div>

    <script>

    document.getElementById("output").innerHTML = "hello world"; 

    </script> 

  • 01-09-2009 5:32 PM In reply to

    Re: Example: PHP show friends page

    Daniel:

    <?php
        $user = $_GET["id"];
      require_once('Space.php');
      $key = 'XXXXXXXXXXXXXXXXXXXXXXXX';
      $secret = 'XXXXXXXXXXXXXXXXXXXXXXXXX';
      $s = new Space($key,$secret);
      $hProfile = $s->profile($user);
      foreach($hProfile as $k => $value){
          echo "<BR><strong>".$k."</strong>:".$value;
      }

     

     

    Wow!  This is so insecure...  All this requires is someone to know the myspaceid of another user of your app, and placing it on the end of your apps url   http://someurl.com?id=xxxxxxxx  and bang!  They are authenticated into your app.

     

     

     

  • 03-10-2009 8:12 PM In reply to

    Re: Example: PHP show friends page

    Hi I found this tutorial is not working for me. wht should I do? Please help me

Page 1 of 1 (14 items)