I have an application in which I'm trying to accomplish the following:
1) Display thumbnails of the application owner and all of his friends.
2) When a user clicks on one of the thumbnails, he is shown a list of all photos for that user. (I'm not sure whether you can even access friend's photos, but I haven't gotten that far yet).
So the first part works great. Here are some code snippets:
This method works to get the the container initialized. It then calls getOwnerAndFriends().
public function init():void {
var osToken:String = Application.application.parameters.opensocial_token;
var osSurfaceName:String = Application.application.parameters.opensocial_surface;
MySpaceContainer.instance.init(osToken, osSurfaceName);
getOwnerAndFriends();
}
The getOwnerAndFriends method is very vanilla and works
public function getOwnerAndFriends():void {
//DataRequest returned by newDataRequest actually of type MSDataRequest.
//MSDataRequest includes functions declared in OpenSocial.DataRequest as well as
//the MySpace extensions.
var dr:MSDataRequest = opensocial.newDataRequest() as MyOpenSpace.MSDataRequest;
dr.add(dr.newFetchPersonRequest('OWNER'), 'Owner');
dr.add(dr.newFetchPeopleRequest('OWNER_FRIENDS'), 'OwnerFriends');
dr.send(onLoadPeople);
}
The callback "onLoadPeople" puts the owner and his friends into class variables:
public function onLoadPeople(dataResponse:DataResponse):void {
person = opensocial.Person(dataResponse.get('Owner').getData());
friends = opensocial.Collection(dataResponse.get('OwnerFriends').getData());
}
Then, the application works with the person and friends variables to display them within components. The components have a 'click' event which ends up calling the getPhotos method:
public function getPhotos(friend:Object):void {
theFriend = friend;
var dr:MSDataRequest = opensocial.newDataRequest() as MyOpenSpace.MSDataRequest;
dr.add(dr.newFetchPhotosRequest(friend.getField("ID"), params), 'Photos');
dr.send(onLoadPhotos);
}
When I look at the value of friend.getField(ID), it is what I would expect. It is the ID of the friend or owner that I have clicked on. So I think I'm creating the request correctly. When I look at examples over in the javascript forums, it seems like I'm doing the same thing. Oh, by the way, "params" is declared in the class as
private static var params:Object = {};
So finally, when the callback, onLoadPhotos is called, I just do what is shown below, and it says "BAD_REQUEST" when I run it whether I pass in myself or one of my friends.
private function onLoadPhotos(dataResponse:DataResponse):void {
Alert.show("Let's see what we got: " + dataResponse.get('Photos').getErrorCode());
}
I appreciate any advice.
Thanks,
--JC