2013-02-01 3 views
1

페이스 북 그래프 API에 대한 간단한 질문. 나는 공식 Facebook Graph API PHP SDK을 사용하고 있습니다.페이스 북 그래프 API를 사용하여 웹 페이지에 댓글 달기

나는 또한 내 웹 페이지에 Facebook 소셜 댓글 플러그인 위젯을 포함 시켰습니다. facebook의 Graph api를 사용하여 웹 페이지에 댓글을 게시 할 수 있습니까?

사용자가 내 웹 응용 프로그램에 페이스 북을 사용하여 로그인 한 다음 API를 통해 내 응용 프로그램의 웹 페이지에 페이스 북의 의견을 게시 할 수 있어야합니다. 따라서 위젯은 페이지에 직접 게시 된 모든 주석과 API를 통해 게시 된 주석을 표시합니다.

지금까지, 나는이 AJAX 코드를 시도 :

<?php 
$token = $facebook->getAccessToken(); 
?> 
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" 
type="text/javascript"></script> 
<script type="text/javascript"> 
$.post('https://graph.facebook.com/comments/?ids=http://mywebsite.com/comments.php?id=123',{ name: 'John', message: 'Testing comments', 'method': 'POST', 'format': 'json', 'access_token': '<?php echo $token; ?>'}, 
function(data) {   
}); 
</script> 

을하지만 이것은 OAUTH 예외 반환 : 로그인 URL을 설정하는 동안 나는 충분한 권한을 요청하고

{ 
    "error": { 
     "message": "An unknown error has occurred.", 
     "type": "OAuthException", 
     "code": 1 
    } 
} 

:

$loginUrl = $facebook->getLoginUrl(array(
       'scope' => 'email,publish_stream,publish_actions,read_stream,user_about_me,user_events,create_event' 
      )); 

참고 : 다음 코드를 사용하여 내 페이지에 페이스 북 위젯을 포함하고있다 :

<div class="fb-comments" data-href="http://www.mywebsite.com/comments.php? 
id=<?php echo $_GET['id']; ?>" data-width="370" data-num-posts="5"></div> 

스크립트 : 의견을 게시 올바른 구문되지 않습니다

<div id="fb-root"></div> 
<script>(function(d, s, id) { 
    var js, fjs = d.getElementsByTagName(s)[0]; 
    if (d.getElementById(id)) return; 
    js = d.createElement(s); js.id = id; 
    js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=xxxxxxxxxxxxxxx"; 
    fjs.parentNode.insertBefore(js, fjs); 
}(document, 'script', 'facebook-jssdk'));</script> 


    <div id='fb-root'></div> 
    <script src='http://connect.facebook.net/en_US/all.js'></script> 
    <!--<p><a onclick='postToFeed(); return false;'>Post to Feed</a></p>--> 
    <p id='msg'></p> 

    <script> 
     FB.init({appId: "xxxxxxxxxxxxxxx", status: true, cookie: true}); 

     function postToFeed() { 

     // calling the API ... 
     var obj = { 
      method: 'feed', 
      redirect_uri: 'http://www.mywebsite.com/comments.php?id=<?php echo $_GET['id']; ?>', 
      link: 'https://developers.facebook.com/docs/reference/dialogs/', 
      picture: 'http://fbrell.com/f8.jpg', 
      name: 'Facebook Dialogs', 
      caption: 'Reference Documentation', 
      description: 'Using Dialogs to interact with users.' 
     }; 

     function callback(response) { 
      document.getElementById('msg').innerHTML = "Post ID: " + response['post_id']; 
     } 
     FB.ui(obj, callback); 
     }  
    </script> 

답변

1

. 적어도 postId가 없습니다 : 을 여기에서 당신은 API 호출을 생성하는 JQuery와 $의 .post를 사용할 수 없습니다

$facebook ->api('/'.$post_id.'/comments', 
'post', 
    array(
     'message' => 'users comment', 
    ) 
); 

(PHP는 SDK) API를 통해 호출 방법에 대해 설명합니다. JQuery를 사용하여 내부 API 호출로 PHP 스크립트를 호출하십시오.

+0

나는 무엇을 post_id에 사용할 지 모르겠습니다. 그것은 페이스 북의 의견 위젯을 가지고 내 웹 페이지의 URL입니까? –

+0

postId = 댓글이 속한 게시물의 ID입니다. API가 없으면 코멘트를 달아야 할 위치를 알 수 없습니다. Facebook의 위젯입니까? 그것은 iFrame 기반 또는 Javascript입니까? 너 혼자 작성 했니? –

+0

위젯은 페이스 북에서 가져온 것이 아닙니다. iframe 코드를 사용하여 내 페이지에 위젯을 수동으로 포함 시켰습니다. –

관련 문제