«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Archives
Today
Total
09-22 07:23
관리 메뉴

DevTzu

[OpenSocial] 전체 친구 목록 불러오기 본문

study

[OpenSocial] 전체 친구 목록 불러오기

DevTzu 2011. 3. 25. 14:50
반응형


    
        
    
    
        
		
            var containerDomain;
            var containerType;

            var allFriends = [];
            var limitPerRequest = 20;
            var requestIdx = 0;

            function initApps()
            {
                allFriends = [];
                requestIdx = 0;

                /*
                    컨테이너 종류
                    - www.natecontainer.com : 일촌 컨테이너 OpenSocial 0.8 지원
                    - cyworld.natecontainer.com : 일촌 컨테이너 OpenSocial 0.9 지원
                    - nateon.natecontainer.com : 네이트온 친구 컨테이너 OpenSocial 0.9 지원 (네이트온은 0.9만 지원)
                */

                // 컨테이너 판별
                containerDomain = opensocial.getEnvironment().getDomain();
                containerType = (containerDomain == 'nateon.natecontainer.com' ? 'nateon' : 'cyworld');

                limitPerRequest = (containerType == 'cyworld' ? 20 : 200);
				
                request();
            }
			
            function request()
            {
                var idspec = opensocial.newIdSpec({ "userId" : "OWNER" , "groupId" : "FRIENDS"});
                var req = opensocial.newDataRequest();
                var params = {};
				
                params[opensocial.DataRequest.PeopleRequestFields.FIRST] = requestIdx * limitPerRequest;
                params[opensocial.DataRequest.PeopleRequestFields.MAX] = limitPerRequest;

                req.add(req.newFetchPersonRequest(opensocial.IdSpec.PersonId.OWNER), "get_owner");
                req.add(req.newFetchPeopleRequest(idspec, params), "get_friends");
				
                req.send(response);
            }

            function response(dataResponse)
            {
                var owner = dataResponse.get('get_owner').getData();
                var friends = dataResponse.get('get_friends').getData();
                var friendsIdx;
				
                friends.each(
                    function(person) {
                        if (person) {
                            friendsIdx = allFriends.length;
                            allFriends[friendsIdx] = {};
                            allFriends[friendsIdx]['id'] = person.getId();
                            allFriends[friendsIdx]['displayName'] = person.getDisplayName();
                            allFriends[friendsIdx]['thumbnail'] = person.getField(opensocial.Person.Field['THUMBNAIL_URL']);
                            allFriends[friendsIdx]['profileUrl'] = person.getField(opensocial.Person.Field['PROFILE_URL']);
                        }
                    });
				
                if (friends.getTotalSize() > (requestIdx + 1) * limitPerRequest)
                {
                    requestIdx++;
                    request();
                }
                else
                {
                    displayFriends(allFriends);
                }
            }
			
            function displayFriends(allFriends)
            {
                var html = '';
							
                for (var i = 0; i < allFriends.length; i++)
                {
                    html += '
'; html += '
' + '
  • DisplayName : ' + allFriends[i].displayName + ' (' + allFriends[i].id + ')
  • '; html += '
    ' + '
  • Thumbnail : ' + allFriends[i].thumbnail + '
  • '; html += '
    ' + '
  • ProfileUrl : ' + allFriends[i].profileUrl + '
  • '; html += '
    '; } document.getElementById("message").innerHTML = html; } // Execute the request function when the application is finished loading. gadgets.util.registerOnLoadHandler(initApps);
    ]]>

    반응형
    Comments