본문 바로가기

기타/소스

페이스북 내 페이지에 예약 걸기

 

//////////////////////////

<!-- fb_share.php -->
<meta charset="UTF-8">
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery.min.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
 
<link rel="stylesheet" href="//cdn.rawgit.com/fgelinas/timepicker/master/jquery.ui.timepicker.css">
<script src='//cdn.rawgit.com/fgelinas/timepicker/master/jquery.ui.timepicker.js'></script>
<script>
$(function() {
    $('.timepicker').timepicker();
 $( "#datepicker1" ).datepicker({
  dateFormat: 'yy-mm-dd',
  prevText: '이전 달',
  nextText: '다음 달',
  monthNames: ['1월','2월','3월','4월','5월','6월','7월','8월','9월','10월','11월','12월'],
  monthNamesShort: ['1월','2월','3월','4월','5월','6월','7월','8월','9월','10월','11월','12월'],
  dayNames: ['일','월','화','수','목','금','토'],
  dayNamesShort: ['일','월','화','수','목','금','토'],
  dayNamesMin: ['일','월','화','수','목','금','토'],
  showMonthAfterYear: true,
  yearSuffix: '년'
 });
});
function asd(){
 var t_date = $("#datepicker1").val();//선택날짜
 $(".timepicker").val("");

 var d = new Date();
 var month = (d.getMonth() + 1);
 if(month<10){
  month = "0"+month;
 }
 var date = +d.getDate();
 if(date<10){
  date = "0"+date;
 }
 var n_date = d.getFullYear()+"-"+month+"-"+date;//현재날짜
 $(".timepicker").attr("onchange","asd2();");
 if(n_date>t_date){//선택날짜가 오늘보다 빠르면
  alert("선택할수 없는 날입니다.");
  $("#datepicker1").val("");
  $(".timepicker").removeAttr("onchange");
 }
}
function asd2(){
 var t_date = $("#datepicker1").val();//선택날짜
 var t_time = $(".timepicker").val();//선택날짜

 var d = new Date();
 var n_date = d.getFullYear()+"-"+(d.getMonth() + 1)+"-"+d.getDate();//현재날짜
 var n_time =  d.getHours()+":"+d.getMinutes();//현재날짜

 if(t_date==n_date){//선택일이 오늘이라면
  if(n_time>t_time){
   alert("현재보다 이전시간입니다.");
   $(".timepicker").val("");
  }
 }
}
</script>
<script>
window.fbAsyncInit = function() {
 FB.init({
  appId      : '', // 앱 ID
  status     : true,          // 로그인 상태를 확인
  cookie     : true,          // 쿠키허용
  xfbml      : true           // parse XFBML
 });

 FB.getLoginStatus(function(response) {
  if (response.status === 'connected') {
   FB.api('/me?fields=id,name,accounts.limit(300)', function(user) {
    $(".fb_login").remove();
    if (user) {
     console.log(user);
     page_token_array = user.accounts.data;
     for(var i=0;i<page_token_array.length;i++){
      $(".aaa").append("<p><input type='checkbox' class='page_list' name='page_list[]' value='"+page_token_array[i].id+"/"+page_token_array[i].access_token+"'>"+page_token_array[i].name+"</p>");
     }
    }
   });   

  } else if (response.status === 'not_authorized') {
  } else {
  }
           
  FB.Event.subscribe('auth.login', function(response) {
   document.location.reload();
  });
  
  FB.Event.subscribe('auth.logout', function(response) {
   document.location.reload();
  });
 });

};

(function(d){
 var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
 if (d.getElementById(id)) {return;}
 js = d.createElement('script'); js.id = id; js.async = true;
 js.src = "//connect.facebook.net/ko_KR/all.js";
 ref.parentNode.insertBefore(js, ref);
}(document));
</script>
<style>
p{margin:0;}

section{max-width:1000px;width:100%;margin:0 auto;text-align:center;}
.fb_form{width:300px;box-sizing: border-box;border:1px solid #e2e2e2;padding:10px;margin:0 auto;}
.fb_form h4{margin-top:0;}
.fb_form input{width:100%;box-sizing: border-box;padding:5px;margin:2px 0;}
.send_btn{margin:20px auto;}
.aaa{width:300px;text-align:left;margin:0 auto;}
</style>
<section>
<div class="fb_login" style="padding-bottom:20px;">
<p>페이스북 로그인부터 해주세요.</p>
<div class="fb-login-button" data-max-rows="1" data-size="medium" data-show-faces="false" data-auto-logout-link="false"></div>
</div>


<form class="fb_form" name="fb_form" action="fb_share_e.php" method="post">
 <input type="text" id="datepicker1" class="t_date" name="t_date" onchange="asd();" >
 <input type="text" class="timepicker t_time" name="t_time" >
 <input type="hidden" name="fb_name" class="fb_name" value="제목">
 <input type="hidden" name="fb_des" class="fb_des" value="내용">
 <input type="hidden" name="fb_pic" class="fb_pic" value="썸네일">
 <input type="hidden" name="fb_link" class="fb_link" value="링크">
 <input type="hidden" name="fb_site" class="fb_site" value="페이지 제목">
 <input type="text" name="fb_message" class="fb_message" placeholder="추가할 메세지" >
 <input type="hidden" name="fb_token" class="fb_token" value="">
 <!--<input type="submit">-->
</form>

<div class="send_btn" value="0" style="border:1px solid #e2e2e2;cursor:pointer;width:60px;padding:3px 8px;text-align:center;border-radius:5px;">전송</div>
<div class="aaa">
<p><input type="checkbox" id="check_all">전체선택</p>

</div>
</section>

 

<script>
$(document).ready(function(){
 $(".send_btn").click(function(){
  var i = 0;
  $(".page_list:checked").each(function(index){
   var window_name="popupView"+i;
   var aaa = $(this).val();
   if(aaa!=0){
    //alert(window_name);
    window.open('',window_name,"width=200,height=200");  

    $(".fb_token").val(aaa);
    document.fb_form.target=window_name;
    document.fb_form.submit();
   }
   i++;
  });
  setTimeout(function() {location.href="";},1000);//돌아갈 url
 });
 
    $("#check_all").click(function(){
        var chk = $(this).is(":checked");//.attr('checked');
        if(chk) $(".page_list").prop('checked', true);
        else  $(".page_list").prop('checked', false);

    });
});
</script>

 

 

 

 

 

 

///////////////////////

<!-- fb_share_e.php -->

<?php
header("Content-Type: text/html; charset=UTF-8");
$t_date = $_REQUEST["t_date"];
$t_time = $_REQUEST["t_time"].":00";

$timestamp = strtotime($t_date." ".$t_time);
$fb_message = $_REQUEST["fb_message"];
$fb_link = $_REQUEST["fb_link"];
$fb_pic = $_REQUEST["fb_pic"];
$fb_name = $_REQUEST["fb_name"];
$fb_site = $_REQUEST["fb_site"];
$fb_des = $_REQUEST["fb_des"];

$fb_token = $_REQUEST["fb_token"];
$fb_token = explode("/",$fb_token);
?>

<!doctype html>

<!--XML namespace 추가-->
<html xmlns:fb="http://ogp.me/ns/fb#">
<meta charset="UTF-8">
<body>
 <div id="fb-root"></div>
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
 <script>
  var page_token_array;

          window.fbAsyncInit = function() {
            FB.init({
              appId      : '', // 앱 ID
              status     : true,          // 로그인 상태를 확인
              cookie     : true,          // 쿠키허용
              xfbml      : true           // parse XFBML
            });
            FB.getLoginStatus(function(response) {
                if (response.status === 'connected') {                   
                    FB.api('/me?fields=id,name,accounts.limit(300)', function(user) {
                        if (user) {
       page_token_array = user.accounts.data;
       postToFeed();
                        }
                    });   
                    
                } else if (response.status === 'not_authorized') {
                } else {
    }
            });

           
            FB.Event.subscribe('auth.login', function(response) {
                document.location.reload();
            });
           
            FB.Event.subscribe('auth.logout', function(response) {
                document.location.reload();
            });
          };
       
           
          //Feed백에 글남기는 method
          function postToFeed (){
     var page_token = "<?=$fb_token[1]?>";
     var path = "/<?=$fb_token[0]?>/feed";
    
     var obj = {
     message: '<?=$fb_message?>',
     access_token : page_token,
     link: '<?=$fb_link?>',
     picture: '<?=$fb_pic?>',
     name: '<?=$fb_name?>',
     caption: '<?=$fb_site?>',
     description: '<?=$fb_des?>',
     scheduled_publish_time:<?=$timestamp?>,
     published:false
    };      
    var body = 'Reading JS SDK documentation';
    FB.api(path, 'post',obj, function(response) {
      if (!response || response.error) {
     console.log(response.error);
     window.location.reload(true);
      } else {
     console.log(response.id);
     window.close();
      }
    });
         };


          // Load the SDK Asynchronously
          (function(d){
             var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
             if (d.getElementById(id)) {return;}
             js = d.createElement('script'); js.id = id; js.async = true;
             js.src = "//connect.facebook.net/ko_KR/all.js";
             ref.parentNode.insertBefore(js, ref);
           }(document));
        </script>

 <p>등록중...</p>

</body>
</html>

 

 

 

 

 

망할 페이스북...

fb_share.php 에서 내 페이지 목록을 띄우고 선택해서 워하는 페이지에 예약거는 코드

중간에 보면 .limit(숫자) 가 붙어있는데 기본적으로 25개 까지 보여주기에 붙여줌
 

'기타 > 소스' 카테고리의 다른 글

php mysql 컬럼수 확인  (0) 2016.01.25
유튜브 내가 필요한 태그  (0) 2016.01.13
facebook_login.php  (0) 2015.11.23
php 페이징  (0) 2015.10.13
모바일 접속 구분  (0) 2015.05.21