Archive

Archive for October, 2012

ปัญหา facebook share แบบ iframe

October 25, 2012 Leave a comment

เมื่อสั่งให้ขึ้น share หลังจากทำรายการส่งขึ้นมูลเข้าเว็บ ในรูปแบบส่งมาหน้าถัดไปแล้วขึ้น dialog share เลย ถ้าเกิดเจอปัญหา session key expire ให้ลองทำตามนี้

1. เช็ค token ว่าถูกต้องหรือไม่ มีหรือไม่ ในขั้นตอนการแสดงผล share แบบ iframe ต้องมี token ใน function ของ js ที่ใช้ด้วย

2. ใส่ set timeout ให้ function ที่ใช้ share ปัญหานี้เจอมากับตัว ใช้ document ready ก็ยังมีปัญหา ให้สั่ง Delay แทนไปเลยซัก 1-2 วินาที

3. อย่าลืม ไฟล์ js หลักของ facebook และ div root ของ facebook

ตัวอย่างเต็ม
<script type="text/javascript">
  FB.init({appId: "xxxxxxxxxxx", status: true, cookie: true, xfbml  : true});
  function postToFeed() {
    var obj = {
      method: 'feed',
      display: 'iframe',
      link: 'ลิ้งค์แชร์',
      picture: 'ลิ้งค์รูป',
      name: 'ชื่อแชร์',
      caption: 'ข้อความย่อแชร์',
      description: 'ข้อความ',
      app_id: "xxxxxxxxxxx", 
      access_token: "token ของสมาชิกนั้นๆ" 
    }; 
      function callback(response) { 
         document.getElementById('msg').innerHTML = "Post ID: " + response['post_id']; 
      } 
      FB.ui(obj, callback); 
     } 
     setTimeout(function() { postToFeed(); }, 1000); 
</script>
Categories: ETC