Created
February 16, 2009 07:39
-
-
Save jfahrenkrug/65067 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<Module> | |
<ModulePrefs | |
title="Owner ID Test" | |
height="600"> | |
<Require feature="opensocial-0.7"/> | |
</ModulePrefs> | |
<Content type="html"> | |
<![CDATA[ | |
<script src="http://www.google.com/jsapi"></script> | |
<script>google.load("jquery", "1.2.6");</script> | |
<script> | |
// owner id | |
var ownertest = function() { | |
var that = { | |
getOwner : function() { | |
var req = opensocial.newDataRequest(); | |
var params = {}; | |
params[opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS]=[opensocial.Person.Field.GENDER, opensocial.Person.Field.PROFILE_URL]; | |
req.add(req.newFetchPersonRequest("OWNER", params), "owner"); | |
req.send(that.getOwnerCallback); | |
}, | |
getOwnerCallback: function(data) { | |
if (data.get("owner").hadError()) { | |
console.log("setupViewerOwnerIdsCallback had error"); | |
} else { | |
var owner = data.get("owner").getData(); | |
var owner_id = owner.getId(); | |
var owner_network_uid = ''; | |
//Orkut specific | |
if (opensocial.getEnvironment().getDomain() == 'orkut.com') { | |
var profile_url = owner.getField(opensocial.Person.Field.PROFILE_URL); | |
var regex = /uid=([^&#]+)/; | |
var result = profile_url.match(regex); | |
if (result.length == 2) { | |
owner_network_uid = result[1]; | |
/* uid now contains the viewer's orkut UID */ | |
} else { | |
/* there was a problem getting the UID */ | |
} | |
} | |
$('#owner-span').html(owner_id); | |
$('#owner-uid-span').html(owner_network_uid); | |
} | |
} | |
}; | |
return that; | |
}(); //notice that the function is invoked right away | |
gadgets.util.registerOnLoadHandler(ownertest.getOwner); | |
</script> | |
<h2>Owner ID</h2> | |
<p>The owner has the id <span id="owner-span"></span>!</p> | |
<h2>Owner Orkut UID</h2> | |
<p>The owner has the orkut uid <span id="owner-uid-span"></span>!</p> | |
<p>(2009, <a href="http://blog.springenwerk.com">Johannes Fahrenkrug</a>)</p> | |
]]> | |
</Content> | |
</Module> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment