그누보드 페이스북 댓글 공유 오류 및 문의2 채택완료

7년 전 조회 2,373

안녕하세요.

 

기존 문의에 대한 명확한 해결방안이 모색되지 않아 문의드립니다.

 

기존문의 : https://sir.kr/qa/254833

 

페이스북 로그인까지는 되는데 댓글 공유시 문제가 발생합니다.

 

댓글 공유버튼의 회색으로 활성화 되지 않고 해당 부분에 대한 오류를 해결하고자 살펴보고 있습니다.

 

현재 페이스북으로 로그인했음에도 댓글 공유시 호출하는 /plugin/sns/facebook/callback.php의

Copy
$user = $facebook->getUser();
에서 값을 제대로 가져오지 못하고 있습니다. 즉 $user = 0의 값을 가져옵니다.

 

callback.php 코드는 아래와 같습니다.

 

Copy
<?php
include_once("./_common.php");
include_once(G5_SNS_PATH."/facebook/src/facebook.php");

$facebook = new Facebook(array(
    'appId'  => $config['cf_facebook_appid'],
    'secret' => $config['cf_facebook_secret']
));

$user = $facebook->getUser();

 

if ($user) {
    try {
        $user_profile = $facebook->api('/me');
    } catch (FacebookApiException $e) {
        error_log($e);
        $user = NULL;
    }
}

$g5['title'] = '페이스북 콜백';
include_once(G5_PATH.'/head.sub.php');

if ($user) {
    $sns_name = $user_profile['name'];
    $sns_user = $user;
    
    set_cookie('ck_sns_name', $sns_name, 86400);
    set_session('ss_facebook_user', $user);

    $g5_sns_url = G5_SNS_URL;

    echo <<<EOT
    <script>
    $(function() {
        document.write("<strong>페이스북 승인이 되었습니다.</strong>");

        var opener = window.opener;
        opener.$("#wr_name").val("{$sns_name}");
        opener.$("#facebook_icon").attr("src", "{$g5_sns_url}/icon/facebook.png");
        opener.$("#facebook_checked").attr("disabled", false);
        opener.$("#facebook_checked").attr("checked", true);
        window.close();
    });
    </script>
EOT;

} else {

    echo <<<EOT
    <script>
    $(function() {
        alert("페이스북 승인이 되지 않았습니다.");
        window.close();
    });
    </script>
EOT;

}

include_once(G5_PATH.'/tail.sub.php');
?>

 

그에따라 결과는 "페이스북 승인이 되지 않았습니다."라는 alert을 요청하고 window가 닫힙니다.

 

appid와 secret 값은 다시 이상없음을 확인하였습니다.

 

$user = $facebook->getUser(); 콜을 따라 base_facebook.php의 getUser 메소드를 살펴본 결과 아래와 같이 나타납니다.

 

Copy
/**
   * Get the UID of the connected user, or 0
   * if the Facebook user is not connected.
   *
   * @return string the UID if available.
   */
  public function getUser() {
    if ($this->user !== null) {
      // we've already determined this and cached the value.
      return $this->user;
    }

    return $this->user = $this->getUserFromAvailableData();
  }

 

  /**
   * Determines the connected user by first examining any signed
   * requests, then considering an authorization code, and then
   * falling back to any persistent store storing the user.
   *
   * @return integer The id of the connected Facebook user,
   *                 or 0 if no such user exists.
   */
  protected function getUserFromAvailableData() {
    // if a signed request is supplied, then it solely determines
    // who the user is.
    $signed_request = $this->getSignedRequest();
    if ($signed_request) {
      if (array_key_exists('user_id', $signed_request)) {
        $user = $signed_request['user_id'];

        if($user != $this->getPersistentData('user_id')){
          $this->clearAllPersistentData();
        }

        $this->setPersistentData('user_id', $signed_request['user_id']);
        return $user;
      }

      // if the signed request didn't present a user id, then invalidate
      // all entries in any persistent store.
      $this->clearAllPersistentData();
      return 0;
    }

 

  /**
   * Retrieve the signed request, either from a request parameter or,
   * if not present, from a cookie.
   *
   * @return string the signed request, if available, or null otherwise.
   */
  public function getSignedRequest() {
    if (!$this->signedRequest) {
      if (!empty($_REQUEST['signed_request'])) {
        $this->signedRequest = $this->parseSignedRequest(
          $_REQUEST['signed_request']);
      } else if (!empty($_COOKIE[$this->getSignedRequestCookieName()])) {
        $this->signedRequest = $this->parseSignedRequest(
          $_COOKIE[$this->getSignedRequestCookieName()]);
      }
    }
    return $this->signedRequest;
  }

 

0을 리턴함에 따라 페이스북으로 연결되지 않은것으로 판단됩니다.

 

페이스북 로그인 되어 있는데 페이스북으로 연결되지 않았다니 의아합니다.

 

혹시 session 등에 저장이 안된것인지요..

 

페이스북 로그인시 session에 저장하는 코드가 어디있는지 궁금합니다.

 

또한, 최근 페이스북 댓글 관련 연동하신 고수님들의 조언을 부탁드립니다.

 

저의 페이스북 세팅과 관련해서는 이전 게시글에서 자세히 살펴보실 수 있습니다.

https://sir.kr/qa/254833

 

그럼 조언을 부탁드립니다.

 

감사합니다.

답변 1개

채택된 답변
+20 포인트

페이스북 사이트에서 sns api 설정 댓글 권한을 열어주세요.

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

천사별님 페북사이트가서 찾아봤는데 어디인줄 모르겠습니다. 연결된 개인페북사이트가 아닌가요? 안내주신 키워드로 N버 검색해도 도대체 안나와서 좀더 자세한 안내 가능하실까요 ㅜㅜ

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인
🐛 버그신고