[ php ] facebook sharer를 이용할 경우 부가 메타데이터 넣는 방법 > php

본문 바로가기

사이트 내 전체검색

php

[ php ] facebook sharer를 이용할 경우 부가 메타데이터 넣는 방법

작성일 18-09-19 15:50

페이지 정보

작성자 웹지기 조회 15,250회 댓글 0건

본문

페이스북 쉐어러를 사용할때는

http://www.facebook.com/sharer/sharer.php?u=공유할 url 만 입력하면 된다.


하지만,

해당 URL에 대한 대표 이미지나, 설명같은 것은 무작위 또는 가장 강조되는 테그를 가져오기때문에

목적이 그냥 특정 URL을 공유하는 것이라면 상관없지만 이게아니라면

의도치않은 결과가 나올 수 있다.

  

이런 부분을 해소하기 위해서 페이스북에서는 메타데이터를 이용해 특정 정보를 가져온다.


추가할 수 있는 메타 데이터들에는 url, type, title, description, image가 있다.

추가하는 방법은 head에 메타데이터를 넣으면 되는데 og: prefix를 통해 페이스북이 데이터를 긁어간다.


<meta property="og:title" content="페이지정보" />

<meta property="og:image" content="상품이미지 사진" />

<meta property="og:description" content="상품설명 넣는부분" />

<meta property="og:type" content="website" />

위처럼 넣으면

해당 데이터를 긁어서 쉐어러정보가 들어간다.


하지만 이런식으로 넣어도 쉐어러에 들어가는 정보에 대한 캐쉬를 남기기 때문에

같은 URL에서는 동일한 정보를 가져온다.

한달에 한번정도 갱신이 되는거라서 실시간 반영하는 방법을 찾는도중에

http://developers.facebook.com/tools/debug/og/object

을 이용하면 실시간으로 갱신이 되는것을 알게되었다.


http://developers.facebook.com/tools/debug/og/object?q=특정 url 을 이용하면 해당 URL 을 거친것과 같은 결과를 내므로

공유전에 한번 돌려주는 작업을 처리하면 구현이 가능하다.



<script>

function go_sns(SNS,siteContent,siteshort,siteUrl)

{

    var siteUrl = siteUrl;

    var siteContent = encodeURI(siteContent);

    var siteshort = encodeURI(siteshort);

    var siteBody = "\""+siteContent+"\":"+siteUrl; // me2day 용 (링크 액션 줄 수 있도록)


    if(SNS == "facebook") {    

        window.open("http://www.facebook.com/sharer.php?u="+siteUrl+"&t="+siteContent+"","SNS_pop","width=800 height=600"); 

    }else if(SNS == "twitter"){        

       window.open("http://twitter.com/share?text="+siteContent+"&url="+siteUrl+"","SNS_pop","width=800 height=600");    

    }else if(SNS == "me2day"){        

       window.open("http://me2day.net/posts/new?new_post[body]="+siteBody+"&new_post[tags]="+siteshort+"","SNS_pop","width=800 height=600");    

    }else if(SNS == "cyworld"){

       window.open("http://csp.cyworld.com/bi/bi_recommend_pop.php?url="+siteUrl+"&"+siteContent+"","SNS_pop","width=800 height=600");    

    }else if(SNS == "daum"){

       window.open("http://yozm.daum.net/api/popup/prePost?link="+siteUrl+"&prefix="+siteContent+"","SNS_pop","width=800 height=600");

    }

}

</script>

<a onclick="go_sns('facebook','<?=$it[it_name]?>','1stzone','http://1stzone.com/web/shop/item.php?it_id=<?=$it[it_id]?>')" href="javascript:;"><img src="<?=$item_skin_path?>/img/facebook.gif" alt="facebook" /></a>


추천0

비추천 0

댓글목록

등록된 댓글이 없습니다.

전체 82건 4 페이지

이미지 목록

게시물 검색
Copyright © 즐거운 코딩 생활 ( funyphp ). All rights reserved.
PC 버전으로 보기