2011-10-04 5 views
0

저는 현재 Facebook을 통해 로그인 할 수있는 웹 사이트에서 작업 중이며, 모든 정보가 내 사이트에서 사용됩니다.Facebooks 개발자 API를 사용하여 사용자의 친구 정보에 액세스합니다.

예 : 독신이거나 여성 남성 또는 둘 다에 관심이있는 경우.

페이스 북 개발자 측에서 사이트의 주변을 둘러 보았고 거기에 어떤 영화에 대한 정보를 얻으려는 샘플 코드가 있습니다. 그래서 변경하고 적응할 수 있는지 궁금 해서요. 나는 필요하다.

Facebook Graph API

:

http://developers.facebook.com/blog/post/481

<div id="fb-root"></div> 
<script src="http://connect.facebook.net/en_US/all.js# 
appId=YOUR_APP_ID&amp;xfbml=1"></script> 

<fb:login-button show-faces="true" width="200" max-rows="1" 
perms="user_likes, friends_likes"></fb:login-button> 

FB.api('/me/friends', function(response) { }); 
FB.api(‘/USER_ID/movies’, function(response) { }); 


FB.api('/'+movieListSorted[i].id, function(response) { 
    var newDiv = document.createElement("DIV"); 
    newDiv.innerHTML = "<img src='"+response.picture+"'></img><br/>"; 
    if(response.link) { 
    newDiv.innerHTML+="<a href='"+response.link+"'>"+response.link 
    +"</a><br/>"; 
    newDiv.innerHTML+='<iframe src="http://www.facebook.com' 
    + '/plugins/like.php?' 
    + 'href='+response.link+'&amp;layout=standard&amp;' 
    + 'show_faces=true&amp;' 
    + 'width=450&amp;action=like&amp;colorscheme=light' 
    + '&amp;height=80"' 
    + 'scrolling="no" frameborder="0" style="border:none;' 
    + 'overflow:hidden;' 
    + 'width:450px; height:80px;" allowTransparency="true"> 
    + '</iframe><br/>'; 
    } 
    document.getElementById(response.id).appendChild(newDiv); 
}); 


<html> 
<head> 
<title>Test Page</title> 
<script> 
    var movieList = new Array(); 
    var movieListSorted = new Array(); 
    var friendCount = 0; 
    function showMovies() { 
    alert(movieList.length); 
    } 
    function compareMovies(movieA, movieB) { 
    if (movieA.name === movieB.name) return 0; 
    if (movieA.name > movieB.name) return 1; 
    return -1; 
    } 
    function popularMovies(movieA, movieB) { 
    return movieB.mCount - movieA.mCount; 
    } 
    function data_fetch_postproc() { 
    document.getElementById('test').innerHTML 
     = "Generating recommendations ... "; 
    movieList.sort(compareMovies); 
    // Now we have sorted list, dedupe and count 
    mCtr = 0; 
    for (i = 0; i < movieList.length; i++) 
    { 
     var count = 0; 
     movieListSorted[mCtr] = movieList[i]; 
     for (j = i; j < movieList.length; j++) 
     { 
     if (movieList[i].name === movieList[j].name) { 
      count++; 
     } else { 
      break; 
     } 
     } 
     i = i+count-1; 
     movieListSorted[mCtr++].mCount = count; 
    } 
    var maxResults = 100; 
    if(movieListSorted.length < 100) { 
     maxResults = movieListSorted.length; 
    } 
    movieListSorted.sort(popularMovies); 
    document.getElementById('test').innerHTML = ""; 
    for(i=0; i<maxResults; i++) { 
     var newDiv = document.createElement("DIV"); 
     newDiv.id = movieListSorted[i].id; 
     newDiv.innerHTML = movieListSorted[i].name + ' : Likes - ' 
     + movieListSorted[i].mCount; 
     document.getElementById("movies").appendChild(newDiv); 
     FB.api('/'+movieListSorted[i].id, function(response) { 
     var newDiv = document.createElement("DIV"); 
     newDiv.innerHTML = "<img src='"+response.picture+"'>" 
      + "</img><br/>"; 
     if(response.link) { 
      newDiv.innerHTML+= "<a href='"+response.link+"'>" 
      +response.link+"</a><br/>"; 
      newDiv.innerHTML+= '<iframe src=' 
      + '"http://www.facebook.com/plugins/like.php?' 
      + 'href='+response.link+'&amp;layout=standard' 
      + '&amp;show_faces=true&amp;' 
      + 'width=450&amp;action=like&amp;' 
      + 'colorscheme=light&amp;height=80"' 
      + 'scrolling="no" frameborder="0" style="' 
      + 'border:none; overflow:hidden;' 
      + 'width:450px; height:80px;"' 
      + 'allowTransparency="true"></iframe><br/>'; 
     } 
     document.getElementById(response.id).appendChild(newDiv); 
     }); 
    } 
    } 
    function get_friend_likes() { 
    document.getElementById('test').innerHTML = "Requesting " 
     + "data from Facebook ... "; 
    FB.api('/me/friends', function(response) { 
     friendCount = response.data.length; 
     for(i=0; i<response.data.length; i++) { 
      friendId = response.data[i].id; 
      FB.api('/'+friendId+'/movies', function(response) { 
      movieList = movieList.concat(response.data); 
      friendCount--; 
      document.getElementById('test').innerHTML = friendCount 
       + " friends to go ... "; 
      if(friendCount === 0) { data_fetch_postproc(); }; 
      }); 
     } 
     }); 
    } 
</script> 
</head> 
<body> 
<div id="fb-root"></div> 
<div id="login"></div> 
<div id="test"></div> 
<div id="movies"></div> 
<script src="http://connect.facebook.net/en_US/all.js"></script> 
<script> 
FB.init({ 
    appId : 'YOUR_APP_ID', 
    status : true, // check login status 
    cookie : true, // enable cookies 
    xfbml : true // parse XFBML 
    }); 
FB.Event.subscribe('auth.sessionChange', function(response) { 
    window.location.reload(); 
}); 
FB.getLoginStatus(function(response) { 
    if (response.session) { 
    // logged in and connected user, someone you know 
    get_friend_likes(); 
    document.getElementById('login').innerHTML 
     ='<a href="#" onclick="FB.logout();">Logout</a><br/>'; 
    } else { 
    document.getElementById('login').innerHTML 
     ='<fb:login-button show-faces="true" width="200"' 
     + ' max-rows="1" perms="user_likes, friends_likes">' 
     + '</fb:login-button>'; 
    FB.XFBML.parse(); 
    } 
}); 
</script> 
</body> 
</html> 

답변

1

당신은 그래프 API를 체크 아웃 적이 :

여기에 일부 코드 나는이 페이지에서 발견하고 그것을 설명 어디 또한 적절한 사용 권한이 있는지 확인해야합니다.

Facebook API Permissions

0

특히 초보자 인 경우이 정보를 얻으려면 PHP SDK를 사용하는 것이 좋습니다. 그러면 해당 기능을 사용할 수 있습니다.

다음과 같은 URL에서 (일부 문서 포함)이 소스 코드를 찾을 수 있습니다

: 그래프 API에서 무엇을 얻기 위해, 모든 https://developers.facebook.com/docs/reference/php/

첫째, 당신은 인증을 획득해야합니다 응용 프로그램에 대한 사용자의이 여기에 설명되어 있습니다 :

https://developers.facebook.com/docs/authentication/

그런 다음 API 호출을 사용하여 현재 사용자에 대한 필요한 정보를 얻을 수 있습니다. 이 여기에 설명되어 있습니다 :

try { 

     $user_profile = $facebook->api('/me?fields=interested_in','GET'); 
     echo "Interested in: " . $user_profile['interested_in']; 

     } catch(FacebookApiException $e) { 
     // Failed API call 
     error_log($e->getType()); 
     error_log($e->getMessage()); 
     } 
:

http://developers.facebook.com/docs/reference/php/facebook-api/

여기 노트의 아래의 코드는,이 문서화 here로 현재 사용자의 필드 '관심 _'에 로그인을 제공하기 위해 편집 한한다

관련 문제