添加Facebook应用程序停止工作 - getsession停止工作

时间:2011-12-18 16:56:25

标签: php facebook sdk oauth-2.0

我使用php sdk拥有这个简单的iframe应用。突然,新的Facebook用户无法将其添加为应用程序。  我尝试了新的php SDK示例,但没有成功。

一个。我在这里包含代码,如果有人可以给我指点。

湾我愿意雇用某人来进行纠正。

<?php

require 'facebook.php';

$test = 0;

if ($test == 1) {
   $appCanvasPage = 'https://apps.facebook.com/myapptest/';
   $app_id = "";
   $app_secret = "";
}
else {
   $appCanvasPage = 'https://apps.facebook.com/myapp/';
   $app_id = "";
   $app_secret = "";
}



$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));


$session = $facebook->GetSession();

$loggedin = 0;

echo "status ".$_GET['installed'];
echo "\n\nsession=".$session;

if (!empty($session)) {

   //echo "status ".$_GET['installed'];

   if ($_GET['installed'] == '1') {
      header("Location: $appCanvasPage");
   }

   try {
      $uid = $facebook->getUser();
      $user = $facebook->api('/me');

   }  catch (Exception $e) {}

   if (!empty($user)) {
      $loggedin = 1;
      echo "Hello ".$user['first_name'];
   }
   else {
      $url = $facebook->getLoginUrl();
      echo "<a href='".$url."'> Click Here </a> to Add the Facebook MyApp\n";
   }
}
else {
   //$url = $facebook->getLoginUrl();

   $url = $facebook->getLoginUrl(array('canvas' => 1,
                                       'fbconnect' => 0,
                                       'req_perms' => '',
                                       'next' => $appCanvasPage.'index.php',
                                       'cancel_url' => $appCanvasPage ));  

   echo $url;
   echo "<a href='".$url."'> Click Here </a> to Add the Facebook MyApp\n";
}


?>

<?php if ($loggedin == 1) { ?>
<pre>
   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
   <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
   <head>

   <script type="text/javascript" language="JavaScript1.2" src="https://www.myappwebsite.com/myapp.js"></script>

   <style type="text/css">
   body {
   width:530px;
   height:600px
   margin:0; padding:0; border:0;
   font: bold 14px Arial, Helvetica, sans-serif;
   }
   </style>
   <meta http-equiv="Content-Type" content="text/html;
   charset=iso-8859-1" />
   </head>
   <body>
   <div id="container">
   <center>
   <table border=0 width="90%" cellspacing="0" cellpadding="0">
   <tr><td align="left">
   <center>
   <table border="0" cellspacing="0" cellpadding="5" width="80%" class="headers2">
   <tr>
      <td valign="top" align="center">

      <h2> MY APP WILL GO HERE </h2>

      </td>
   </tr>
   </table>
   </center>
   </form>


   </center>
   </div>
   </body>
   </html>
<?php } else { ?>

<?php } ?>

1 个答案:

答案 0 :(得分:0)

这看起来你必须将Facebook php-sdk更新到最新版本。 请参阅开发者博客上的帖子:Upgrade to PHP SDK v3.0.0

您也可以阅读帖子:

Breaking Change: JavaScript SDK to oauth:true on December 13th(这可能是你的应用程序停止工作,正如许多其他人一样,看到该帖子的评论)

Updated JavaScript SDK and OAuth 2.0 Roadmap

BTW,旧版本的php-sdk有函数getSession,它可能像GetSession一样工作,但如果你注意变量/函数名,你会节省很多时间......只是IMO ......