2013-03-18 2 views
0

내 페이지에서 사람들은 공유 버튼을 누르고 Facebook에 게시 할 수 있습니다.응답. 이름 또는 ID를 얻으려고 시도합니다.

window.fbAsyncInit = function() { 
    FB.init(
    { 
     "appId" : "<?php echo $fbid; ?>", 
     "status" : true, 
     "cookie" : true, 
     "xfbml" : true, 
     "oauth" : true 
    }); 

기능 showStreamPublish을 클릭에 시작 : 은이 코드를 사용하여 나는 다음과 같은 코드를 사용

function showStreamPublish() { 
     FB.ui(
      { 
      method: 'feed', 
      name: 'Text', 
      caption: 'Text', 
      link: 'Link', 
      picture:'Pic', 
      description: 'ni', 
      user_message_prompt: 'Share it!' 

      }, 
      function(response) { 
       if (response && response.post_id) { 



        FB.api('/me', function(response) 
     {alert(response.name); 
     }); ... 

내가 Sahre을했던 사람의 이름을 보여 싶어하지만 :(나던

FB.api('/me', function(response) 
     {alert(response.name); 
     }); 

어떻게 사용자 이름 또는 공유했던 persob의 사용자 ID를 얻을 수 그것은 경고-상자를 엽니 다 - 컨텐츠로서 "정의되지 않은"로 . 도움 주셔서 감사합니다.

response.status를 얻으 려하고 이상한 점은 : 내 앱을 통해 연결하여 Facebook에 게시하더라도 내 앱을 통해 연결되지 않는다는 메시지가 나타납니다. 그 코드 사용 :

if (response.status === 'connected') { 
    // the user is logged in and has authenticated your app 
    alert('All good'); 
    }else if (response.status === 'not_authorized') { 
    // the user is logged in but NOT through your app 
    alert('Not good'); 
    }else{ 
    alert('What the heck?');// the user isn't logged in to Facebook. 
    } 
}); 

+0

의 중복 가능성 [페이스 북 기능 (응답) (http://facebook.stackoverflow.com/questions/15427821/facebook-functionresponse) – CBroe

답변

1

내가 생각하지 않는 두 가지를 참조하면 좋다 :

  • FB.api 호출 FB.ui에 포함되어 있습니다.
  • 당신은 두 번 response 사용
    • FB.ui({...}, function(response) {...,
    • FB.api('/me', function(response) {....

두 문제는 관련 여부를 할 수있다. 하지만이 그것을 만들 것입니다 :

function showUserName() { 
    FB.api('/me', function(response) { 
     alert('Post was published by ' + response.name); 
    }); 
} 
function showStreamPublish() { 
    FB.ui({ 
     method: 'feed', 
     name: 'Text', 
     caption: 'Text', 
     link: 'Link', 
     picture: 'Pic', 
     description: 'ni', 
     user_message_prompt: 'Share it!' 
    }, function(response) { 
     if (response && response.post_id) { 
      showUserName(); 
     } else { 
      alert('Post was not published.'); 
     } 
    } 
); 
+0

들으 지금까지. 그러나 여기에서도 "게시물은 정의되지 않은 채 게시되었습니다."라는 메시지가 표시됩니다. 나는 더 많은 코드를 사용하지 않으며 페이스 북에서의 게시물은 성공적이다. –

+0

코드를 업데이트했습니다. –

+0

그것의 이상한, 아직도 점점 : 게시물은 정의되지 않은에 의해 게시되었습니다. 나는 이유를 모른다. 앱이 사용자 데이터에 액세스 할 수 있고 사용자가 연결되어 게시물이 성공적인 것입니다! –

관련 문제