Hi,
We
are having difficulty in obtaining viewerId and ownerId in the
profile surface for our apps. We are currently using opensocial 0.8
(although the difficulty also occurs in 0.7). The code below works in
FireFox and IE when only one app using this method is present in the
profile page.
The
difficulty occurs when we try and use this opensocial technique with
more than one app in the profile page. At this point the behaviour of
IE and FireFox diverge.
(example
results when using two apps)
FireFox
sends only one opensocial get request, and thus only one app renders
output, the other never gets to run the handleOpenSocialResponse
function, thus stalling.
It appears that the first (to be run by firefox) app's javascript is
the one that emits an opensocial get request, the result being only
one random app working.
IE
7 renders both apps (thus sending and receiving two separate
opensocial requests) about 80% of the time, the remaining 20% of the
time only one opensocial request is sent, and thus only one app
renders.
In
both cases it appears to be req.send(handleOpenSocialResponse);
that does not emit the correct
number of calls.
Please
help, we have two apps that need to work in the profile page.
A
generalization of the code we're using in both apps follows. Are we
doing something dumb – or have we run into something arcane?
<div
class="ourapp">
<div
id="report" class="report"></div>
<script
language="JavaScript">
//
<!--
var
req = opensocial.newDataRequest();
function
handleOpenSocialResponse(result) {
var
owner = result.get("owner");
owner_data
= owner.getData();
var
viewer = result.get("viewer");
viewer_data
= viewer.getData();
var
viewerId;
if
(!viewer_data) { viewerId = 'unknown' }
else
{ viewerId = viewer_data.getId() }
var
report = document.getElementById('report');
report.innerHTML
= 'ownerId:' + owner_data.getId() + '<br/>viewerId:' +
viewerId;
}
function
getOpenSocialData() {
req.add(req.newFetchPersonRequest(opensocial.DataRequest.PersonId.OWNER),"owner");
req.add(req.newFetchPersonRequest(opensocial.DataRequest.PersonId.VIEWER),"viewer");
req.send(handleOpenSocialResponse);
}
getOpenSocialData();
//
-->
</script>
Note:
this doesn't work at all in opera, altough i've seen several other
forum threads that touch on this issue. eg.
http://developer.myspace.com/Community/forums/p/6479/33821.aspx#33821
http://developer.myspace.com/Community/forums/p/6778/33824.aspx#33824
An
easy way to view this behaviour is to install our two apps and allow
both in your profile and watch. If either app is installed it should
render ok, if both are the the oddness starts.
App
A:
http://profile.myspace.com/index.cfm?fuseaction=user.viewProfile&friendID=402805525
App
B:
http://profile.myspace.com/index.cfm?fuseaction=user.viewProfile&friendID=402804969