我的画布应用程序保持清爽

时间:2012-12-10 21:49:06

标签: php facebook

我在我的应用程序中使用此代码以允许用户登录以及获取创建和编辑用户事件的应用程序权限,并且它工作正常,但是当我今天尝试它时页面保持刷新无限以及每次更改身份验证代码。我不知道发生了什么事。

<?php
   // Include facebook php api 
   require_once("lib/facebook.php");

    // Setup app configuration
    $config = array();
    $config['appId'] = 'APP_ID';
    $config['secret'] = 'APP_SECRET';
    $config['cookie'] = true;
    $config['fileUpload'] = true;

    // set app id & canvas page for location variable
    $app_id = 'APP_ID';
    $canvas_page = "https://apps.facebook.com/mixityhc/";

      $location = "https://www.facebook.com/dialog/oauth?client_id=" 
         . $app_id . "&redirect_uri=" . urlencode($canvas_page) . "&scope=publish_stream,email,create_event,rsvp_event,user_events,friends_events";

  // create new instance of facebook object
  $facebook = new Facebook($config);

    // Get user id
    $fbID = $facebook->getUser();

    // Get the current access token
    $access_token = $facebook->getAccessToken();

    // check if we have valid user
 if ($fbID) {
     try {
          // Proceed knowing you have a logged in user who's authenticated.
         $fb_user_profile = $facebook->api('/me');   

      } catch (FacebookApiException $e) {
          $fbID = NULL;
          // seems we don't have enough permissions
          // we use javascript to redirect user instead of header() due to Facebook bug
          print '<script language="javascript" type="text/javascript"> top.location.href="'. $location .'"; </script>';

         // kill the code so nothing else will happen before user gives us permissions
         die();
      }

  } else {
      // seems our user hasn't logged in, redirect him to a FB login page

     print '<script language="javascript" type="text/javascript"> top.location.href="'. $location .'"; </script>';

     // kill the code so nothing else will happen before user gives us permissions
     die();
 }

 // Get user email address
 $email = $fb_user_profile['email'];

非常感谢任何帮助,谢谢

1 个答案:

答案 0 :(得分:0)

好的,我明白了。 Facebook API已更新,以修复Facebook中的明显错误。所以我上传了新文件(特别是证书)并且它有效。以防万一其他人遇到同样的问题。

由于