OpenSocialTutorial-11

IDtail.com API

Jump to: navigation, 찾기

[편집] 어플리케이션 추천하기

어플리케이션을 추천하는 기능은 idtail의 고유기능입니다. 하지만, 어플리케이션에서도 이 기능을 이용할 수 있습니다.

opensocial.requestShareApp( [ 'id1', 'id2', 'id3' ], callback );

함수를 호출해 주시면 됩니다.

<Module>
 <ModulePrefs title="My Friends List">
   <Require feature="opensocial-0.7"/>
 </ModulePrefs>
 <Content type="html">
   <![CDATA[
   <div id="content"></div>
   <script type="text/javascript" >
	gadgets.util.registerOnLoadHandler( init );

	function init() {
		var req = opensocial.newDataRequest();
		req.add( req.newFetchPersonRequest('VIEWER'), 'viewer' );
		req.add( req.newFetchPeopleRequest('VIEWER_FRIENDS'), 
				'viewerFriends' );
		req.send( onDataLoad );
	}

	function afterShare(data)
	{
		if( data.hadError() ) {
			alert("Failed to share");
		} else {
			alert("Shared");
		}
	}

	function share()
	{
		var ids = new Array();
		for( var i=0; i<document.forms['friends'].length; i++ ) {
			if( document.forms['friends'].elements[i].checked ) {
				ids.push( document.forms['friends'].elements[i].value );
			}
		}
		opensocial.requestShareApp( ids, afterShare );
	}

	function onDataLoad(dataResponse) { /* dataResponse methods: hadError get */
		var cont = document.getElementById('content');

		if( dataResponse.hadError() ) {
			cont.innerHTML = "Error in fetching data";
			return;
		}

		var viewerFriends = 
				dataResponse.get( 'viewerFriends' ).getData();

		var c;
		c = '<h1>Viewer\'s Friends Information</h1>';
		c += '<form name="friends"><ol>';
		viewerFriends.each( function(person) {
			c += '<li style="display:inline">' +
			  '<label>' +
			  '<input type="checkbox" name="p" value="' +
			  person.getId()+'" />' + 
			  person.getDisplayName() + '</label></li>';
		} );
		c += '</ol>';
		c += '<input type="button" '+
			'value="Share with these friends!"'+
			'onclick="share();" /></form>';

		cont.innerHTML = c;

	}
	</script>
	]]>
</Content>
</Module>


이전 페이지 | 다음 페이지