2012-01-11 1 views
-3

페이스 북에서 팀의 Flash 프로젝트를 얻으려고하고 있지만 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를 변경하는 유일한 두 개의 선이있는 APPID 비밀 : 여기 내 파일 구조입니다.

의 index.php : this 예를 들어 다음과 같은 경우

<?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> 

나는 같은 "예상치 못한 '{'"오류가 발생했습니다.

내가 뭘 잘못하고 있니?

+4

잘'line 36' 무엇입니까? 그래서 우리에게 줄 번호를 매기 지 않는다. – 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

관련 문제