2013-03-24 9 views
3

php를 사용하여 앱의 콘텐츠에 액세스하려는 사람이 특정 페이스 북 그룹의 구성원인지 확인하는 방법에 대한 예가 있습니까? 나는 개발자 문서를 읽었으며, 그 일을 할 수있는 모든 것은 나를 혼란스럽게 만들었다. 나는 이것과 비슷한 게시물을 보았지만 회원 목록을 인쇄하는 방법을 보여주었습니다 ...사용자가 특정 페이스 북 그룹의 구성원인지 확인

목록을 얻는 방법과 그 응용 프로그램에 액세스하려는 사용자가 회원인지 확인해야합니다 그룹 중 하나를 선택하면 액세스 허용 또는 거부 : 액세스를 거부하고 그룹 페이지로 사용자를 리디렉션하여 회원을 요청할 수 있습니다.

답변

4

네, 매우 간단합니다. 사용자가 원하는 그룹의 ID를 입력하고 범위 user_groups 권한을 요청하여 사용자가 가진 그룹을 쿼리 할 수 ​​있습니다. PHP는 SDK와

당신은이 작업을 수행 할 수 있습니다

<?php 
    // Remember to copy files from the SDK's src/ directory to a 
    // directory in your application on the server, such as php-sdk/ 
    require_once('php-sdk/facebook.php'); 

    $config = array(
    'appId' => 'YOUR_APP_ID', 
    'secret' => 'YOUR_APP_SECRET', 
); 

    $facebook = new Facebook($config); 
    $user_id = $facebook->getUser(); 
if($user_id) { 

     // We have a user ID, so probably a logged in user. 
     // If not, we'll get an exception, which we handle below. 
     try { 

     $user_profile = $facebook->api('/me?fields=id,name,groups','GET'); 
     $user_belongs_to_group= FALSE; 
     foreach($user_profile['groups']['data'] as $group){ 
      if($group['id']==YOUR_GROUP_ID) 
      $user_belongs_to_group=TRUE; 
     } 
     if($user_belongs_to_group){ 
     //Alright! the user belongs to the group 
     } 
     else{ 
      //Oh snap you don't belong here, but you can if want to 
     } 

     } catch(FacebookApiException $e) { 
     // If the user is logged out, you can have a 
     // user ID even though the access token is invalid. 
     // In this case, we'll get an exception, so we'll 
     // just ask the user to login again here. 
     $login_url = $facebook->getLoginUrl(); 
     echo 'Please <a href="' . $login_url . '">login.</a>'; 
     error_log($e->getType()); 
     error_log($e->getMessage()); 
     } 
    } else { 

     // No user, print a link for the user to login 
     $login_url = $facebook->getLoginUrl(); 
     echo 'Please <a href="' . $login_url . '">login.</a>'; 

     } 

?> 

나는 페이스 북에서 잡고이 코드의 일부, 당신은 반환되는 데이터를 볼 수있을 때 여기에 그룹에 대한 쿼리 : https://developers.facebook.com/tools/explorer

보도 이름 뒤에 더하기 기호는 연결로 이동하고 그룹을 선택하고 보내기를 누르십시오

0

당신은 catch-22에 있습니다. 사용자는 user_groups 권한을 통해 그의 그룹에게 권한을 부여해야합니다.