2012-01-11 12 views
-3

私のチームのFlashプロジェクトをFacebookで入手しようとしていますが、PHP-SDKの例は動作しません。私はgithub(here)のこの新しいもののようないくつかの例を続けました。しかし、私は解析エラーを受け取り続けます:構文エラー、予期せぬ「{」Facebook PHP-SDKを使用している場合

Parse error: syntax error, unexpected '{' in /home/content/r/a/s/rashomon/html/projects/facebook/test/hellomyflash/index.php on line 36

私は最新のPHP-SDKをダウンロードしました。私のファイル構造は次のとおりです。

.../hellomyflash/ 

    index.php 

    src/base_facebook.php 

    src/facebook.php 

    src/fb_ca_chain_bundle.crt 

私がindex.phpで変更した唯一の2行はappIdとsecretです。

のindex.php:

<?php 
/** 
* Copyright 2011 Facebook, Inc. 
* 
* Licensed under the Apache License, Version 2.0 (the "License"); you may 
* not use this file except in compliance with the License. You may obtain 
* a copy of the License at 
* 
*  http://www.apache.org/licenses/LICENSE-2.0 
* 
* Unless required by applicable law or agreed to in writing, software 
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 
* License for the specific language governing permissions and limitations 
* under the License. 
*/ 

require '../src/facebook.php'; 

// Create our Application instance (replace this with your appId and secret). 
$facebook = new Facebook(array(
    'appId' => '###############', 
    'secret' => '################################', 
)); 

// Get User ID 
$user = $facebook->getUser(); 

// We may or may not have this data based on whether the user is logged in. 
// 
// If we have a $user id here, it means we know the user is logged into 
// Facebook, but we don't know if the access token is valid. An access 
// token is invalid if the user logged out of Facebook. 

if ($user) { 
    try { 
    // Proceed knowing you have a logged in user who's authenticated. 
    $user_profile = $facebook->api('/me'); 
    } catch (FacebookApiException $e) { 
    error_log($e); 
    $user = null; 
    } 
} 

// Login or logout url will be needed depending on current user state. 
if ($user) { 
    $logoutUrl = $facebook->getLogoutUrl(); 
} else { 
    $loginUrl = $facebook->getLoginUrl(); 
} 

// This call will always work since we are fetching public data. 
$naitik = $facebook->api('/naitik'); 

?> 
<!doctype html> 
<html xmlns:fb="http://www.facebook.com/2008/fbml"> 
    <head> 
    <title>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>php-sdk</h1> 

    <?php if ($user): ?> 
     <a href="<?php echo $logoutUrl; ?>">Logout</a> 
    <?php else: ?> 
     <div> 
     Login using OAuth 2.0 handled by the PHP SDK: 
     <a href="<?php echo $loginUrl; ?>">Login with Facebook</a> 
     </div> 
    <?php endif ?> 

    <h3>PHP Session</h3> 
    <pre><?php print_r($_SESSION); ?></pre> 

    <?php if ($user): ?> 
     <h3>You</h3> 
     <img src="https://graph.facebook.com/<?php echo $user; ?>/picture"> 

     <h3>Your User Object (/me)</h3> 
     <pre><?php print_r($user_profile); ?></pre> 
    <?php else: ?> 
     <strong><em>You are not Connected.</em></strong> 
    <?php endif ?> 

    <h3>Public profile of Naitik</h3> 
    <img src="https://graph.facebook.com/naitik/picture"> 
    <?php echo $naitik['name']; ?> 
    </body> 
</html> 

this例を以下のとき、私は同じ "予期しない '{'" エラーが発生しました。

私は間違って何をしていますか?

+4

よく 'line 36'とは何ですか? SOは行番号を付けません – Jakub

答えて

5

あなたのサーバはPHP4を実行している可能性が高く、提供されるコードはPHP5用です。

PHP4にはtry/catchブロックがありません。

+0

正確には、36行目は 'try {'です。 –

+0

それは問題だったようです。今、別の問題です。認証要求が発行されていません。それから、「ウェブサイトはページを表示できません」という灰色のiframeが表示されます。私はhttp://developers.facebook.com/blog/post/503/から公式FBコードを使用しています。私はこれのための新しいスレッドを開始する必要がありますか? – user359519

+0

はい、解決してください、すでに解決された質問を手助けすることを望む多くの人ではありません。 –

0

"facebook.php"と "base_facebook.php"に行くと、ページの下部にある "?>"のphpの終了タグがありません。私はこれがいくつかの問題を引き起こしたと聞いてきました。近くのタグを追加すると修正されました。あなたが試すことができます;)

私の上の男の答えを見た後、それはおそらく正解です! :p

関連する問題