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