facebook 实时更新不会发布到 callback.php
Posted
技术标签:
【中文标题】facebook 实时更新不会发布到 callback.php【英文标题】:facebook real-time updates doesn't post to callback.php 【发布时间】:2012-10-24 19:10:13 【问题描述】:我在这里订阅https://developers.facebook.com/apps/301135526661971/realtime?save=1 实时更新成功“测试”没问题。我的“字段”设置为“online_presence”、“朋友”、“状态”、“状态”,但 Facebook 从不更新我!?这是我的callback.php:
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script type="text/javascript" src="jquery-1-7-2.js"></script>
<style>
bodyfont-style:normal;font-size;12px/1.1em;font-family:"lucida grande",tahoma,verdana,arial,sans-serif;line-height:1.4em;font-size:62.5%;background-color:#FFFFFF;
A.update:link text-decoration:none;color:#DEE3ED;font-weight:bold;
A.update:visited text-decoration:none;color:#DEE3ED;font-weight:bold;
A.update:active text-decoration:none;color:#DEE3ED;font-weight:bold;
A.update:hover text-decoration:none;color:#FFF;font-weight:bold;
.Bfwidth:183px;height:34px;background-color:#FAFAFA;border-style:none;border-top-style:solid;border-top-width:1px;border-color:#D8DFEA;
</style>
<script>
var NN = 0;
var Q; //FQL
var meid,me;//Qid is every one including me
window.fbAsyncInit = function()
FB.init( appId:'0000000000',status:true,cookie:true,xfbml:true,oauth:true,hideFlashCallback:true);
FB.getLoginStatus(function(response)
if(response.status==='connected')
FB.api('/me',function(response)me=response.name;meid=response.id;getFriends(););
else
FB.login(function(response)if(response.authResponse)
FB.api('/me',function(response)me=response.name;meid=response.id;getFriends(););
,scope:'friends_online_presence,user_status,user_birthday,friends_birthday,publish_stream,user_photos,friends_photos');
);;
var Pt1 = '<div class="Bf"value="';
var Pt2 = '"title="';
var Pt3 = '"><img style="margin:2px;"align="left"src="http://graph.facebook.com/';
var Pt4 = '/picture?type=square"/>';
var Pt0 = '<br><span id="BD"></span></div>';
function getFriends()
Q=FB.Data.query("SELECT name,uid,online_presence FROM user WHERE (online_presence=='active' OR online_presence=='idle') AND uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) ORDER BY online_presence");
Q.wait(function(rows)$.each(rows,function(index,f)
//
if(f.online_presence=='active') $('#non').append(Pt1+f.uid+Pt2+f.name+Pt3+f.uid+Pt4+'<a href="http://facebook.com/'+f.uid+'"target="_blank">'+f.name+'</a><br><img src="R/fbactive.png"></div>');
else if(f.online_presence=='idle') $('#non').append(Pt1+f.uid+Pt2+f.name+Pt3+f.uid+Pt4+'<a href="http://facebook.com/'+f.uid+'"target="_blank">'+f.name+'</a><br><img src="R/fbidle.png"></div>');
//
$('.Bf').unbind().bind('hover',function()$(this).css("background-color","#FFFFFF");,function()$(this).css("background-color","#FAFAFA");).bind('click',function());
NN++;
if(NN==rows.length)
NN=0;$('#Flist').prepend('<img style="margin:2px;height:30px;"align="left"src="http://graph.facebook.com/'+meid+'/picture?type=square"/><b>'+me+'</b><br><br><br>');
););
</script>
</head><body>
<?php define('VERIFY_TOKEN','011235813');$method = $_SERVER['REQUEST_METHOD'];if($method=='GET' && $_GET['hub_mode']=='subscribe' && $_GET['hub_verify_token']==VERIFY_TOKEN) echo $_GET['hub_challenge'];else if($method=='POST')$updates=json_decode(file_get_contents('php://input'),true);echo $updates; ?>
<div id="fb-root"></div>
<div id="Flist"
style="position:absolute;width:183px;left:0px;
background-color:#F2F2F2;
border-color:#D8DFEA;
border-width:1px;
border-style:solid;
overflow:auto;
overflow-x:hidden;">
<div id="non"style="width:183px;"></div>
<br>
</div>
<script type="text/javascript">
/*END fbAsyncInit*/(function()var e = document.createElement('script'); e.async = true;e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';document.getElementById('fb-root').appendChild(e);());
</script>
</body></html>
我所有的代码都在这里,我很难过为什么我什么也没听到?
更新!
我尝试只使用 php:
<?php
require "facebook.php";
$facebook = new Facebook(array('appId' => '000000','secret' => '0000',));
$user = $facebook->getUser();
if($user)
try
$me = $facebook->api('/me');
echo 'logged in';
define('VERIFY_TOKEN','011235813');
$method = $_SERVER['REQUEST_METHOD'];
if($method=='GET' && $_GET['hub_mode']=='subscribe' && $_GET['hub_verify_token']==VERIFY_TOKEN) echo $_GET['hub_challenge'];
else if($method=='POST')$updates=json_decode(file_get_contents('php://input'),true);echo $updates;
catch(FacebookApiException $e)$user=null;
?>
但 facebook 仍然没有发布到我的回调...
更新:
【问题讨论】:
请注意,您不能订阅用户对象的所有属性和连接的更改。您可以订阅的连接包括:供稿、朋友、活动、兴趣、音乐、书籍、电影、电视、喜欢、签到、位置、事件。 所以他们只提供用户表的一部分嗯......那么我别无选择,只能每隔几秒钟在那里轮询一次!干得好脸书! 想想我错了,或者facebook错了!这里出了点问题......(见我上面的图片) 【参考方案1】:online_presence
无法通过实时更新获得,可能的字段是
【讨论】:
【参考方案2】:如果您想要用户状态消息的实时更新,您必须在订阅中启用“提要”(在“字段”下)。
【讨论】:
以上是关于facebook 实时更新不会发布到 callback.php的主要内容,如果未能解决你的问题,请参考以下文章
Facebook SDK 登录永远不会在 iOS 9 上回调我的应用程序
Facebook:用于订阅用户到 Facebook(webhook)以进行实时更改的图形 api 是啥