Javascript奇怪的错误:“意外”)'“

时间:2013-03-14 11:34:27

标签: php javascript error-handling compiler-errors

在我的“index.php”文件中执行简单的js函数时,我遇到了一个非常奇怪的错误。我有以下功能:

function popLikes()
   {
    window.open("likes.php", "Like" "height = 300, width = 400")
    }

错误是:SyntaxError: missing ) after argument list @ http://localhost:8080/index.php:38

指示的序列是:

$facebook = new Facebook(array(          //line 38
'appId'  => AppInfo::appID(),
'secret' => AppInfo::appSecret(),
'sharedSession' => true,
'trustForwarded' => true,
));

完整的php,请求如下:

<?php

/**
* This sample app is provided to kickstart your experience using Facebook's
* resources for developers.  This sample app provides examples of several
* key concepts, including authentication, the Graph API, and FQL (Facebook
* Query Language). Please visit the docs at 'developers.facebook.com/docs'
* to learn more about the resources available to you
*/

// Provides access to app specific values such as your app id and app secret.
// Defined in 'AppInfo.php'
require_once('AppInfo.php');

// Enforce https on production
if (substr(AppInfo::getUrl(), 0, 8) != 'https://' && $_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
header('Location: https://'. $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
exit();
}

// This provides access to helper functions defined in 'utils.php'
require_once('utils.php');


/*****************************************************************************
*
* The content below provides examples of how to fetch Facebook data using the
* Graph API and FQL.  It uses the helper functions defined in 'utils.php' to
* do so.  You should change this section so that it prepares all of the
* information that you want to display to the user.
*
****************************************************************************/
$testfile="testfile.txt";
$testfile_out=fopen($testfile,'w') or die("Can't test file");
require_once('sdk/src/facebook.php');

$facebook = new Facebook(array(
'appId'  => AppInfo::appID(),
'secret' => AppInfo::appSecret(),
'sharedSession' => true,
'trustForwarded' => true
));
$myfile="testson.json";
$fileout=fopen($myfile,'w') or die("Fatal: Can't write to JSON file");
$user_id = $facebook->getUser();
if ($user_id) {
try {
  // Fetch the viewer's basic information
  $user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
  // If the call fails we check if we still have a user. The user will be
  // cleared if the error is because of an invalid accesstoken
  if (!$facebook->getUser()) {
    header('Location: '. AppInfo::getUrl($_SERVER['REQUEST_URI']));
    exit();
  }
}
if($user_id)
{
  $logoutUrl=$facebook->getLogoutUrl();
}
  else
  {
      $loginUrl=$facebook->getLoginUrl();
  }

// This fetches some things that you like . 'limit=*" only returns * values.
// To see the format of the data you are retrieving, use the "Graph API
// Explorer" which is at https://developers.facebook.com/tools/explorer/
$likes = idx($facebook->api('/me/likes?limit=5000'), 'data', array());

// This fetches 4 of your friends.
$friends = idx($facebook->api('/me/friends?limit=4'), 'data', array());

// And this returns 16 of your photos.
$photos = idx($facebook->api('/me/photos?limit=16'), 'data', array());
//fwrite($fileout,json_encode($likes));
// Here is an example of a FQL call that fetches all of your friends that are
// using this app
$app_using_friends = $facebook->api(array(
  'method' => 'fql.query',
  'query' => 'SELECT uid, name FROM user WHERE uid IN(SELECT uid2 FROM friend WHERE uid1 = me()) AND is_app_user = 1'
));
}

// Fetch the basic info of the app that they are using
$app_info = $facebook->api('/'. AppInfo::appID());

$app_name = idx($app_info, 'name', '');

?>
<!DOCTYPE html>
<html xmlns:fb="http://ogp.me/ns/fb#" lang="en">
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=2.0, user-scalable=yes" />

  <title><?php echo he($app_name); ?></title>
  <link rel="stylesheet" href="stylesheets/screen.css" media="Screen" type="text/css" />
  <link rel="stylesheet" href="stylesheets/mobile.css" media="handheld, only screen and (max-width: 480px), only screen and (max-device-width: 480px)" type="text/css" />

  <!--[if IEMobile]>
  <link rel="stylesheet" href="mobile.css" media="screen" type="text/css"  />
  <![endif]-->

  <!-- These are Open Graph tags.  They add meta data to your  -->
  <!-- site that facebook uses when your content is shared     -->
  <!-- over facebook.  You should fill these tags in with      -->
  <!-- your data.  To learn more about Open Graph, visit       -->
  <!-- 'https://developers.facebook.com/docs/opengraph/'       -->
  <meta property="og:title" content="<?php echo he($app_name); ?>" />
  <meta property="og:type" content="website" />
  <meta property="og:url" content="<?php echo AppInfo::getUrl(); ?>" />
  <meta property="og:image" content=" <?php echo AppInfo::getUrl('/logo.png'); ?>" />
  <meta property="og:site_name" content="<?php echo he($app_name); ?>" />
  <meta property="og:description" content="My first app" />
  <meta property="fb:app_id" content="<?php echo AppInfo::appID(); ?>" />

  <script type="text/javascript" src="/javascript/jquery-1.7.1.min.js"></script>
  <script type="text/javascript">
    function logResponse(response) {
      if (console && console.log) {
        console.log('The response was', response);
      }
    }
    function popLikes()
       {
        window.open("likes.php", "Select the pages that should have your like" "height = 300, width = 300")
        }
    $(function(){
      // Set up so we handle click on the buttons
      $('#postToWall').click(function() {
        FB.ui(
          {
            method : 'feed',
            link   : $(this).attr('data-url')
          },
          function (response) {
            // If response is null the user canceled the dialog
            if (response != null) {
              logResponse(response);
            }
          }
        );
      });

      $('#sendToFriends').click(function() {
          console.error($(this).attr('data-url'));
        FB.ui(
          {
            method : 'send',
            link   : $(this).attr('data-url')
          },
          function (response) {
            // If response is null the user canceled the dialog
            if (response != null) {
              logResponse(response);
            }
          }
        );
      });

      $('#sendRequest').click(function() {
        FB.ui(
          {
            method  : 'apprequests',
            message : $(this).attr('data-message')
          },
          function (response) {
            // If response is null the user canceled the dialog
            if (response != null) {
              logResponse(response);
            }
          }
        );
      });
    });
  </script>

  <!--[if IE]>
    <script type="text/javascript">
      var tags = ['header', 'section'];
      while(tags.length)
        document.createElement(tags.pop());
    </script>
  <![endif]-->
</head>
<body>
  <div id="fb-root"></div>
  <script type="text/javascript">
    window.fbAsyncInit = function() {
      FB.init({
        appId      : '<?php echo AppInfo::appID(); ?>', // App ID
        channelUrl : '//<?php echo $_SERVER["HTTP_HOST"]; ?>/channel.html', // Channel File
        status     : true, // check login status
        cookie     : true, // enable cookies to allow the server to access the session
        xfbml      : true // parse XFBML
      });

      // Listen to the auth.login which will be called when the user logs in
      // using the Login button
      FB.Event.subscribe('auth.login', function(response) {
        // We want to reload the page now so PHP can read the cookie that the
        // Javascript SDK sat. But we don't want to use
        // window.location.reload() because if this is in a canvas there was a
        // post made to this page and a reload will trigger a message to the
        // user asking if they want to send data again.
        window.location = window.location;
      });

      FB.Canvas.setAutoGrow();
    };

    // Load the SDK Asynchronously
    (function(d, s, id) {
      var js, fjs = d.getElementsByTagName(s)[0];
      if (d.getElementById(id)) return;
      js = d.createElement(s); js.id = id;
      js.src = "//connect.facebook.net/en_US/all.js";
      fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));
    // FB.getLoginStatus(function(response) {
    //     if (response.status === 'connected') {
    //         // the user is logged in and has authenticated your
    //         // app, and response.authResponse supplies
    //         // the user's ID, a valid access token, a signed
    //         // request, and the time the access token
    //         // and signed request each expire
    //         var uid = response.authResponse.userID;
    //         var accessToken = response.authResponse.accessToken;
    //     } else if (response.status === 'not_authorized') {
    //         // the user is logged in to Facebook,
    //         // but has not authenticated your app
    //     } else {
    //         // the user isn't logged in to Facebook.
    //     }
    // });
  </script>

  <header class="clearfix">
    <?php if (isset($user_profile)) {
      ?>
    <p id="picture" style="background-image: url(https://graph.facebook.com/<?php echo he($user_id); ?>/x picture?type=normal)"></p>
     <div>
     <section>
      <h1>Welcome, <strong><?php echo he(idx($user_profile, 'name')); ?></strong></h1>
       <?php if($user_id):?>
          <a href="<?php echo $logoutUrl;?>">Logout</a>
      <?php endif ?>
      <p class="tagline">
        This is your app
        <a href="<?php echo he(idx($app_info, 'link'));?>" target="_top"><?php echo he($app_name); ?></a>
      </p>

      <div id="share-app">
        <p>Share your app:</p>
        <ul>
          <li>
            <a href="#" class="facebook-button" id="postToWall" data-url="<?php echo AppInfo::getUrl(); ?>">
              <span class="plus">Post to Wall</span>
            </a>
          </li>
          <li>
            <a href="#" class="facebook-button speech-bubble" id="sendToFriends" data-url="<?php echo AppInfo::getUrl(); ?>">
              <span class="speech-bubble">Send Message</span>
            </a>
          </li>
          <li>
            <a href="#" class="facebook-button apprequests" id="sendRequest" data-message="Test this awesome app">
              <span class="apprequests">Send Requests</span>
            </a>
          </li>
        </ul>
      </div>
    </div>
    <?php } else { ?>
    <div>
      <h1>Welcome</h1>
      <div class="fb-login-button" data-scope="user_likes,user_photos,email, user_birthday,user_groups,email,user_about_me,user_activities,
      user_birthday,user_education_history,user_groups,user_hometown,user_interests,user_likes,user_location,user_questions,user_relationships,
      user_relationship_details,user_religion_politics,user_subscriptions,user_website,user_work_history,user_events,user_games_activity,
      user_notes,user_photos,user_status,user_videos,publish_actions"></div>
    </div>
    <?php } ?>
  </header>

  <section id="get-started">
    <p>Welcome to your Facebook app, running on <span>heroku</span>!</p>
    <a href="https://devcenter.heroku.com/articlxes/facebook" target="_top" class="button">Learn How to Edit This App</a>
  </section>

  <?php
    if ($user_id) {
  ?>

  <section id="samples" class="clearfix">
    <h1>Examples of the Facebook Graph API</h1>

    <div class="list">
      <h3>A few of your friends</h3>
      <ul class="friends">
        <?php
          foreach ($friends as $friend) {
            // Extract the pieces of info we need from the requests above
            $id = idx($friend, 'id');
            $name = idx($friend, 'name');
        ?>
        <li>
          <a href="https://www.facebook.com/<?php echo he($id); ?>" target="_top">
            <img src="https://graph.facebook.com/<?php echo he($id) ?>/picture?type=square" alt="<?php echo he($name); ?>">
            <?php echo he($name); ?>
          </a>
        </li>
        <?php
          }
        ?>
      </ul>
    </div>

    <div class="list inline">
      <h3>Recent photos</h3>
      <ul class="photos">
        <?php
          $i = 0;
          foreach ($photos as $photo) {
            // Extract the pieces of info we need from the requests above
            $id = idx($photo, 'id');
            $picture = idx($photo, 'picture');
            $link = idx($photo, 'link');

            $class = ($i++ % 4 === 0) ? 'first-column' : '';
        ?>
        <li style="background-image: url(<?php echo he($picture); ?>);" class="<?php echo $class; ?>">
          <a href="<?php echo he($link); ?>" target="_top"></a>
        </li>
        <?php
          }
        ?>
      </ul>
    </div>

    <div class="list">
      <h3>Things you like</h3>
      <ul class="things">
   <?php
          $nr_of_likes=0;
          fwrite($fileout, json_encode($likes));
          foreach ($likes as $key=>$like) {
            // Extract the pieces of info we need from the requests above
            $id = idx($like, 'id');
            $item = idx($like, 'name');
            $likes[$key]['type']='like';
              $nr_of_likes++;
            ?>
        <li>
          <a href="https://www.facebook.com/<?php echo $like['id']; ?>" target="_top">
            <img src="https://graph.facebook.com/<?php echo he($id) ?>/picture?type=square" alt="<?php echo $like['name']; ?>">
          </a>
        </li> 

            <?php }
              fwrite($fileout,json_encode($likes));
              //fwrite($fileout,$nr_of_likes);
            // This display's the object that the user liked as a link to
            // that object's page.
        ?>


      </ul>
    </div>

   <!--  <form>

    <input type="button" value="Open window" onclick="popLikes()" />
    </form> -->
  </section>

  <?php
    }
  ?>

  <section id="guides" class="clearfix">
    <h1>Learn More About Heroku &amp; Facebook Apps</h1>
    <ul>
      <li>
        <a href="https://www.heroku.com/?utm_source=facebook&utm_medium=app&utm_campaign=fb_integration" target="_top" class="icon heroku">Heroku</a>
        <p>Learn more about <a href="https://www.heroku.com/?utm_source=facebook&utm_medium=app&utm_campaign=fb_integration" target="_top">Heroku</a>, or read developer docs in the Heroku <a href="https://devcenter.heroku.com/" target="_top">Dev Center</a>.</p>
      </li>
      <li>
        <a href="https://developers.facebook.com/docs/guides/web/" target="_top" class="icon websites">Websites</a>
        <p>
          Drive growth and engagement on your site with
          Facebook Login and Social Plugins.
        </p>
      </li>
      <li>
        <a href="https://developers.facebook.com/docs/guides/mobile/" target="_top" class="icon mobile-apps">Mobile Apps</a>
        <p>
          Integrate with our core experience by building apps
          that operate within Facebook.
        </p>
      </li>
      <li>
        <a href="https://developers.facebook.com/docs/guides/canvas/" target="_top" class="icon apps-on-facebook">Apps on Facebook</a>
        <p>Let users find and connect to their friends in mobile apps and games.</p>
      </li>
    </ul>
  </section>
</body>
</html>

现在真正奇怪的是有一个Error:Unexpected ')' on line ... of index.php。 该函数附近的行甚至,但似乎是在包含右括号')'的随机行上。如果我删除该功能,没有错误,没有问题。 然而,我的代码似乎是有效的(是吗?)。

注意:“likes.php”与我调用该函数的文件位于同一个文件夹中,因此不会出现问题。

我一直在苦苦挣扎,我似乎毫无意义。

注意:AppInfo.php,utils.php和其他都很好,不要打扰他们

1 个答案:

答案 0 :(得分:3)

错误在于:

window.open("likes.php", "Like" "height = 300, width = 400")
                               ^

应该有一个逗号:

window.open("likes.php", "Like", "height = 300, width = 400")