2011-06-09 147 views
0

我正在寻找一个好的,简单的PHP或JS功能来获取我最新的Facebook状态更新。任何人都有很好的解决方案获取Facebook状态

我有一个JS脚本,但只是停止工作。

继承人的代码: view code

提前感谢!

+0

在链接的例子中,我看到了一个错误:“无法加载来源:http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.min.js”听起来像CDN jQuery链接不起作用。 – David 2011-06-09 18:54:46

回答

1

如果你有一个Facebook应用程序,你可以用它来生成一个访问令牌,然后你可以做一个简单的HTTP请求:

https://graph.facebook.com/me/statuses?access_token=2221230867|2.xxxxx.xxxxx

当您通过https://www.facebook.com/developers那里创建一个FB应用是一些示例PHP代码的链接。如果您指定offline_access权限,则访问码不会自动过期。见:http://developers.facebook.com/docs/authentication/

1

万一有人需要它,我有这对MT博客http://dashasalo.com/2011/09/12/get-your-own-facebook-status/这里工作的例子是使用Facebook的例子

// your app id from app settings page 
$app_id = "11111111"; 
// your app secret 
$app_secret = "sdfsdfdsfdsfdsfdf"; 
// url facebook will post data to 
$my_url = "http://dashasalo.com/fbauth.php"; 

session_start(); 
$code = $_REQUEST["code"]; 

if(empty($code)) { 
    $_SESSION['state'] = md5(uniqid(rand(), TRUE)); //CSRF protection 
    $dialog_url = "https://www.facebook.com/dialog/oauth?client_id=" 
    . $app_id . "&redirect_uri=" . urlencode($my_url) . "&state=" 
    . $_SESSION['state'].'&scope=user_status,offline_access'; 

    echo("<script>top.location.href='" . $dialog_url . "'</script>"); 
} 

if($_REQUEST['state'] == $_SESSION['state']) { 
    $token_url = "https://graph.facebook.com/oauth/access_token?" 
    . "client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url) 
    . "&client_secret=" . $app_secret . "&code=" . $code; 

    $response = file_get_contents($token_url); 
    $params = null; 
    parse_str($response, $params); 

    echo("Auth tocken = " . $params['access_token']); 
} 
else { 
    echo("The state does not match. You may be a victim of CSRF."); 
} 

如果一切正常的话,你会得到你的身份验证令牌变形例打印出来。将其复制并粘贴到下面的代码:

$appId = "11111111"; 
$appSecret = "sdfsdfdsfdsfdsfdf"; 
// auth tocken we have just printed out 
$authToken = 'AAAAAABBBBBBBCCCCCCDDDDDDD'; 
// your facebook user id 
$userId = '568864222'; 

$graphUrl = "https://graph.facebook.com/".$userId."/statuses?limit=1&access_token=" . $authToken; 

$statusMessage = json_decode(file_get_contents($graphUrl), true); 
echo ($statusMessage['data'][0]['message']); 

上面的代码将打印出您的最新状态更新。如果你想获得所有状态的列表,只需从url中删除限制。

$graphUrl = "https://graph.facebook.com/".$userId."/statuses?access_token=" . $authToken;