개발자를 위한 OG META TAG 사용법 (Facebook) > html

본문 바로가기
사이트 내 전체검색

html

개발자를 위한 OG META TAG 사용법 (Facebook)

페이지 정보

작성자 서방님 댓글 0건 조회 101회 작성일 15-09-09 17:13

본문

1. Facebook share : 공유하기 Dialog

 - 공유 방법은 총 2가지가 있는데 첫번째로 Link share, 두번째로 Feed share 

 - 일반적으로 우리가 보는 공유하기가 Link share다. Dialog가 뜨면서 공유할 정보와 함께 사용자가 상세설명을 입력할 수 있다. 

 - Head와 Head 사이에 OG Tag 정의와 https://www.facebook.com/sharer/sharer.php로 연결만 시켜주면 돼서 쉽게 사용할 수 있다.

1) Share Link Dialog : The Share Link is the simpler of the two options to use.  You just direct the user to open a link with the URL to share as a parameter.

tIHAyoR6SMx7PDBHxQfJBlw_PSwDEPsu8pgW4LBJECla_pX4y_NDT8YkV1nNSvt-yNSKt4i-znjKiHTPWTVMyq-9v1J1fT3AmPHvxPXmQ8VjVR4fEvvkacVbhg

- >> https://developers.facebook.com/docs/plugins/share-button/


- Facebook API를 써서 공유하는 방법이 Feed share다.

- 함수 안에서 링크의 정보를 정의해서 공유할 수 있는데 좀 복잡하다.


2) Feed Dialog :  a good way to control the specifics of a share post. It is highly customizable and doesn’t rely on Open Graph tags on a page for it’s information.

- >> https://developers.facebook.com/docs/reference/dialogs/feed/



2. 첫번째 방법인 Share Link Dialog를 사용해보자. 


- OG Tag를 정의해준다.

 - 헤드와 헤드 사이에 meta og tag 를 넣어준다.

(* facebook 말고도 google, twitter 에서도 meta tag를 사용한다. facebook 의 meta tag를 og tag라고 부르는 것이다. http://davidwalsh.name/facebook-meta-tags)


 -rootree.net ->> 이게 공유할 페이지이다. 공유하기 다이얼로그를 띄울 때 아래 페이지의 url(rootree.net)을 연결시켜주면, 공유하기 다이얼로그가 띄워지면 아래의 og tag의 정보를 불러온다.



rootree.net 의 index.html

<head>

<link rel="image_src" href="http://img.jpg"/>

<meta property="fb:app_id" content="179242432284377" />

<meta property="og:title" content="test"/>

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

<meta property="og:url" content="http://rootree.net"/>

<meta property="og:description" content="This is a description."/>

<meta property="og:image" content="http://img.jpg"/>

<meta property="og:image:width" content="1200" />

<meta property="og:image:height" content="627" />

</head>

 - 이미지 크기에 대한 정의


3. 공유하기 버튼 정의

 - 공유하기 다이얼로그를 띄울 버튼을 정의해준다.

 - u="url" u 다음에 공유할 url을 입력한다.

 - 해당 url의 html 소스 안에는 head와 head 사이에 og meta tag가 있어야한다!!


2350F54852A1A91C0FB78C

text.html

<button onclick="shareToPopup()">고고고고</button>

<input id="h_url" type="hidden" value="<?=$res[url]?>" />

<input id="h_img" type="hidden" value="<?=$res[image]?>" />

<input id="h_title" type="hidden" value="<?=$res[title]?>" />

<input id="summ" type="hidden" value="<?=$res[summary]?>" />


<script>

shareToPopup : function(url, image, title, summary){

url = $("#h_url").val();

image = $("#h_img").val();

title = $("#h_title").val();

summary = $("#summ").val();

var params = 'u='+encodeURIComponent(url+'?imgname='+image+'&msg='+summary+'&t='+title+"&passerby=1"); //passerby=1은 타인이 담벼락의 링크타고 들어올 때의 flag를 주는 것

window.open('https://www.facebook.com/sharer/sharer.php?'+params, 'sharer', 'width=626,height=1500');

}

</script>

test.php

$res['url'] = "http://rootree.net";

$res['image']= "http://rootree.net/data/".$_GET['imgname'];

$res['title']="SOMECHECK";

$res['summary'] = "http://somecheck.usless.kr";

4. 공유완료!

 - 뉴스피드에 이런식으로 표시된다. 이미지 size가 640X360 이상인 경우부터 아래와 같이 큰 이미지로 바뀐다.

2572DC4852A1A91C2DFB99


4. 공유하기 팝업에서 og tag 못불러올때

 - https://developers.facebook.com/tools/debug/og/object


26355C4B52A1ABAF3CE909


여기서 rootree.net을 넣어 페이스북의 캐시를 삭제해주면 된단다. 위와 같이 제대로 표시되면 og tag가 제대로 적용된 것이다. 즉, 공유하기 다이얼로그에서 제대로 불러와질 수 있다는 말이다. 좀 기다려야되는 경우도 있다고 하니 서두르지 말 것~~


5. Dynamic Meta tag share

http://creativebusinesslabs.com/simple-social-sharing-buttons-in-magento/

http://stackoverflow.com/questions/8431694/generating-facebook-open-graph-meta-tags-dynamically




페이스북은 글 정보를 저장해 두므로 강제로 지정한 정보가 바로 반영되지 않는다.

http://developers.facebook.com/tools/lint

에서 글 주소를 넣으면 저장되었던 글 정보를 바꿀 수 있다.


댓글목록

등록된 댓글이 없습니다.

Total 323건 6 페이지
게시물 검색

회원로그인

접속자집계

오늘
86
어제
84
최대
1,347
전체
154,457
Latest Crypto Fear & Greed Index

그누보드5
Copyright © 서방님.kr All rights reserved.