2011-11-23 5 views
0

페이스 북 그래프 API를 사용하여 테스트 사용자의 친구를 얻으려고하지만 first_name, last_name 등의 다른 세부 정보는 반환하지 않지만 친구의 ID 만 반환합니다. 사용자. 내가 특별히 내가 필요로하는 분야를 (요청이 같이 보입니다) 통과 :페이스 북 그래프 API를 사용하여 테스트 사용자 데이터 액세스

https://graph.facebook.com/me/friends?access_token=...&fields=id%2Cfirst_name%2Clast_name%2Cgender%2Clocale%2Clink%2Clocation%2Cbirthday%2Creligion%2Crelationship_status 

액세스 토큰 테스트 사용자에게 부여 된 토큰 때 내 응용 프로그램에서 테스트 사용자가 로그인.

비슷한 SO 게시물을 찾았지만 해결책이 무엇인지 확실하지 않습니다.

Query test users through Facebook Graph API

답변

1

당신은 앱 access_token를 사용할 필요가 이것은 다음을 수행하여 그래프 API Explorer에서 테스트 할 수 있습니다 : 당신의 응용 프로그램 access_token

  • 이동합니다 Access Token tool

    1. 이동 및 복사 Graph API Explorer으로 이동하고 드롭 다운 목록에서 앱을 선택하십시오.
    2. 쿼리 APP_ID/accounts/test-users?access_token=app_access_token이는 ID 중 하나에 테스트 사용자
    3. 클릭 (이 사용자가 적어도 하나의 다른 테스트 사용자와 친구가되어 있는지 확인)를 검색 및처럼 보이도록 쿼리를 변경할 것입니다 : 작업이 완료 TEST_USER_ID/friends?fields=first_name,last_name,gender&access_token=app_access_token
    4. ! :-)

    UPDATE :
    아래의 의견을 바탕으로, 나는 테스트 사용자의 친구의 생일을 검색하기 위해 노력했지만 결과는 일관성이 있었다.

    • 테스트 사용자의 access_token 사용 : 아이디, 생일, 성별이 검색되었지만 하지 이름 앱 access_token 사용
    • : 검색된 아이디, 이름과 성별을하지만 하지 생일

    다음은 간단한 코드입니다.

    <html xmlns:fb="http://www.facebook.com/2008/fbml"> 
    <head></head> 
    <body> 
    <div id="fb-root"></div> 
    <script> 
    // You can retrieve this from: https://developers.facebook.com/tools/access_token/ 
    var app_access_token = "APP_ACCESS_TOKEN"; 
        window.fbAsyncInit = function() { 
        FB.init({ 
         appId  : 'APP_ID_HERE', // App ID 
         channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File 
         status  : true, // check login status 
         cookie  : true, // enable cookies to allow the server to access the session 
         oauth  : true, // enable OAuth 2.0 
         xfbml  : true // parse XFBML 
        }); 
    
        // Additional initialization code here 
        }; 
    
        // Load the SDK Asynchronously 
        (function(d){ 
        var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;} 
        js = d.createElement('script'); js.id = id; js.async = true; 
        js.src = "//connect.facebook.net/en_US/all.js"; 
        d.getElementsByTagName('head')[0].appendChild(js); 
        }(document)); 
    </script> 
    
    <table id="friends"> 
        <tr> 
         <th>ID</th> 
         <th>Name</th> 
         <th>Gender</th> 
         <th>Birthday</th> 
        </tr> 
    </table> 
    
    <script> 
    function login(app) { 
        FB.login(function(response) { 
         if (response.authResponse) { 
          var obj = {fields: 'name,gender,birthday', limit: 500}; 
          if(app) 
           obj.access_token = app_access_token; 
          FB.api('/'+response.authResponse.userID+'/friends', 'GET', obj, function(response) { 
           console.log(response); 
           if(response && response.data.length) { 
            var html = ''; 
            for(var i=0; i<response.data.length; i++) { 
             html += "<tr>"; 
             html += "<td>" + response.data[i].id + "</td>"; 
             html += "<td>" + response.data[i].name + "</td>"; 
             html += "<td>" + response.data[i].gender + "</td>"; 
             html += "<td>" + response.data[i].birthday + "</td>"; 
             html += "</tr>"; 
            } 
            document.getElementById("friends").innerHTML += html; 
           } 
          }); 
         } else { 
          console.log('User cancelled login or did not fully authorize.'); 
         } 
        }, {scope: 'user_birthday,friends_birthday'}); 
    
    } 
    </script> 
    <button onclick="login();">List Friends With User Token</button> 
    <button onclick="login(1);">List Freinds With App Token</button> 
    </body> 
    </html> 
    

    내 테스트 사용자 계정 중 하나를 사용하여 그 결과
    enter image description here
    처음 세 행은와 "응용 프로그램 토큰와 목록의 freinds"와 나머지 " 토큰 사용자와 목록 친구"로 검색했다.

    결론은 Facebook의 관심입니다.

  • +0

    위의 사용, 나는 FIRST_NAME, 친구의 LAST_NAME 아니라 자신의 생일을 얻을 수 있어요. 또한 appAccessToken을 사용하여 친구의 세부 정보를 가져와야하는 이유는 명확하지 않습니다. – Divick

    +0

    답변을 업데이트 하시겠습니까? 당신의 도움을 주셔서 감사합니다. – Divick

    +0

    @ DivKis01, 내 대답을 업데이트했습니다. – ifaour

    관련 문제