468,766 Members | 1,408 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,766 developers. It's quick & easy.

How to integrate my website to facebook?

semanticnotion
I want to integrate my site to Facebook login system. I google it and at last I find this great tutorial.http://thinkdiff.net/facebook/php-sd...nect-tutorial/

But there is a problem in my authentication.Herehttp://www.cpantry.com/match you can find my test site. I have used php-sdk please help where I make a mistake.
here is code of my index.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     include_once "fbmain.php";
  3.     $config['baseurl']  =   "http://www.cpantry.com/match/index.php";
  4.  
  5.     //if user is logged in and session is valid.
  6.     if ($fbme){
  7.         //Retriving movies those are user like using graph api
  8.         try{
  9.             $movies = $facebook->api('/me/movies');
  10.         }
  11.         catch(Exception $o){
  12.             d($o);
  13.         }
  14.  
  15.         //Calling users.getinfo legacy api call example
  16.         try{
  17.             $param  =   array(
  18.                 'method'  => 'users.getinfo',
  19.                 'uids'    => $fbme['id'],
  20.                 'fields'  => 'name,current_location,profile_url',
  21.                 'callback'=> ''
  22.             );
  23.             $userInfo   =   $facebook->api($param);
  24.         }
  25.         catch(Exception $o){
  26.             d($o);
  27.         }
  28.  
  29.         //update user's status using graph api
  30.         if (isset($_POST['tt'])){
  31.             try {
  32.                 $statusUpdate = $facebook->api('/me/feed', 'post', array('message'=> $_POST['tt'], 'cb' => ''));
  33.             } catch (FacebookApiException $e) {
  34.                 d($e);
  35.             }
  36.         }
  37.  
  38.         //fql query example using legacy method call and passing parameter
  39.         try{
  40.             //get user id
  41.             $uid    = $facebook->getUser();
  42.             //or you can use $uid = $fbme['id'];
  43.  
  44.             $fql    =   "select name, hometown_location, sex, pic_square from user where uid=" . $uid;
  45.             $param  =   array(
  46.                 'method'    => 'fql.query',
  47.                 'query'     => $fql,
  48.                 'callback'  => ''
  49.             );
  50.             $fqlResult   =   $facebook->api($param);
  51.         }
  52.         catch(Exception $o){
  53.             d($o);
  54.         }
  55.     }
  56. ?>
  57. <!DOCTYPE html>
  58. <html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
  59.     <head>
  60.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  61.         <title>PHP SDK & Graph API base FBConnect Tutorial | Thinkdiff.net</title>
  62.     </head>
  63. <body>
  64.     <div id="fb-root"></div>
  65.         <script type="text/javascript">
  66.             window.fbAsyncInit = function() {
  67.                 FB.init({appId: '<?=$fbconfig['appid' ]?>', status: true, cookie: true, xfbml: true});
  68.  
  69.                 /* All the events registered */
  70.                 FB.Event.subscribe('auth.login', function(response) {
  71.                     // do something with response
  72.                     login();
  73.                 });
  74.                 FB.Event.subscribe('auth.logout', function(response) {
  75.                     // do something with response
  76.                     logout();
  77.                 });
  78.             };
  79.             (function() {
  80.                 var e = document.createElement('script');
  81.                 e.type = 'text/javascript';
  82.                 e.src = document.location.protocol +
  83.                     '//connect.facebook.net/en_US/all.js';
  84.                 e.async = true;
  85.                 document.getElementById('fb-root').appendChild(e);
  86.             }());
  87.  
  88.             function login(){
  89.                 document.location.href = "<?=$config['baseurl']?>";
  90.             }
  91.             function logout(){
  92.                 document.location.href = "<?=$config['baseurl']?>";
  93.             }
  94. </script>
  95. <style type="text/css">
  96.     .box{
  97.         margin: 5px;
  98.         border: 1px solid #60729b;
  99.         padding: 5px;
  100.         width: 500px;
  101.         height: 200px;
  102.         overflow:auto;
  103.         background-color: #e6ebf8;
  104.     }
  105. </style>
  106.  
  107.     <h3>PHP SDK & Graph API base FBConnect Tutorial | Thinkdiff.net</h3>
  108.     <?php if (!$fbme) { ?>
  109.         You've to login using FB Login Button to see api calling result.
  110.     <?php } ?>
  111.     <p>
  112.         <fb:login-button autologoutlink="true" perms="email,user_birthday,status_update,publish_stream"></fb:login-button>
  113.     </p>
  114.  
  115.     <!-- all time check if user session is valid or not -->
  116.     <?php if ($fbme){ ?>
  117.     <table border="0" cellspacing="3" cellpadding="3">
  118.         <tr>
  119.             <td>
  120.                 <!-- Data retrived from user profile are shown here -->
  121.                 <div class="box">
  122.                     <b>User Information using Graph API</b>
  123.                     <?php d($fbme); ?>
  124.                 </div>
  125.             </td>
  126.             <td>
  127.                 <div class="box">
  128.                     <b>User likes these movies | using graph api</b>
  129.                      <?php d($movies); ?>
  130.                 </div>
  131.             </td>
  132.         </tr>
  133.         <tr>
  134.             <td>
  135.                 <div class="box">
  136.                     <b>User Information by Calling Legacy API method "users.getinfo"</b>
  137.                     <?php d($userInfo); ?>
  138.                 </div>
  139.             </td>
  140.             <td>
  141.                 <div class="box">
  142.                     <b>FQL Query Example by calling Legacy API method "fql.query"</b>
  143.                     <?php d($fqlResult); ?>
  144.                 </div>
  145.             </td>
  146.         </tr>
  147.     </table>
  148.     <div class="box">
  149.         <form name="" action="<?=$config['baseurl']?>" method="post">
  150.             <label for="tt">Status update using Graph API</label>
  151.             <br />
  152.             <textarea id="tt" name="tt" cols="50" rows="5">Write your status here and click 'submit'</textarea>
  153.             <br />
  154.             <input type="submit" value="Update My Status" />
  155.         </form>
  156.         <?php if (isset($statusUpdate)) { ?>
  157.             <br />
  158.             <b style="color: red">Status Updated Successfully! Status id is <?=$statusUpdate['id']?></b>
  159.          <?php } ?>
  160.     </div>
  161.     <?php } ?>
  162.  
  163.     </body>
  164. </html>
Mar 11 '11 #1
1 6234
serdar
88
What error do you get when trying to login?
Mar 13 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by mfasoccer | last post: by
11 posts views Thread by Dual_b00t | last post: by
George Lft
7 posts views Thread by George Lft | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.