原文網址:http://clonn.blogspot.tw/2011/01/facebook-api-php-sdk.html
以下轉載原文
---------------------------------------------------------------------------------------------
[教學] Facebook API PHP SDK 基本篇. Facebook API PHP SDK Basic introduce.
快速教學如何使用php建構自己的APP
Facebook 中建立application 取得Keys
Facebook developer application page.
進入頁面後如下圖所表示,根據提示快速建立Application.
下載Facebook API for php,把資料解壓縮開來,我們只需要兩個檔案。
1. facebook.php
2. example.php
將兩個檔案放到同個資料夾當中,修改example.php
接著檔案上傳到Server上,執行你的APP。
以下為簡化後的example.php內容。
直接想要看結果,可以點此連到範例頁面,頁面內容如下。
Facebook 中建立application 取得Keys
Facebook developer application page.
進入頁面後如下圖所表示,根據提示快速建立Application.
建立好app,可以進入到內部將Domain name, email, ...等資料補齊。
TIP:Domain name一定要設定好,不然會導致無法使用。
下載Facebook API for php,把資料解壓縮開來,我們只需要兩個檔案。
1. facebook.php
2. example.php
將兩個檔案放到同個資料夾當中,修改example.php
$facebook = new Facebook(array( 'appId' => '你的APP ID', 'secret' => '你的應用程式密鑰', 'cookie' => true, ));
接著檔案上傳到Server上,執行你的APP。
以下為簡化後的example.php內容。
<?php require 'facebook.php'; // Create our Application instance (replace this with your appId and secret). $facebook = new Facebook(array( 'appId' => 'appid', 'secret' => 'secret key', 'cookie' => true, )); $session = $facebook->getSession(); $me = null; // Session based API call. if ($session) { try { $uid = $facebook->getUser(); $me = $facebook->api('/me'); } catch (FacebookApiException $e) { error_log($e); } } if ($me) { $logoutUrl = $facebook->getLogoutUrl(); } else { $loginUrl = $facebook->getLoginUrl(); } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Clonn.info - Facebook API demo PHP SDK</title> <style> body { font-family: 'Lucida Grande', Verdana, Arial, sans-serif; } h1 a { text-decoration: none; color: #3b5998; } h1 a:hover { text-decoration: underline; } </style> </head> <body> <h1>Pure PHP SDK, without javascript</h1> <div> <ul> <li><a href="<?php echo $facebook->getLogoutUrl(); ?>">LogOUT</a></li> <li><a href="<?php echo $facebook->getLoginUrl(); ?>">LogIN</a></li> </ul> </div> <h3>Session</h3> <?php if ($me): ?> <pre><?php print_r($session); ?></pre> <h3>You</h3> <img src="https://graph.facebook.com/<?php echo $uid; ?>/picture"> <?php echo $me['name']; ?> <h3>Your User Object</h3> <pre><?php print_r($me); ?></pre> <?php else: ?> <strong><em>You are not Connected.</em></strong> <?php endif ?> </body> </html>
直接想要看結果,可以點此連到範例頁面,頁面內容如下。
全站熱搜
留言列表