我有一个非常奇怪的问题,我一直在尝试解决一段时间,但它已经到了我无法解决的地步。
我有一个简单的 php 脚本。它执行一些 api 调用并从 facebook 中提取一些数据,然后显示它。出于某种原因,在此页面上,我放入脚本中的任何 Javascript/jquery 都无法正常工作。我在源代码中插入了一个带有 javascript 的 iframe,它可以工作,但如果 javascript 在此页面中,它根本不会注册。根本没有响应..javascript插件不会出现,或者该功能不会在点击时触发。
MYSQL 调用也不起作用。我根本没有得到任何回报。你们以前有过这种情况吗?有什么可能的原因吗?
我不认为我有任何语法错误。不过我会继续检查。任何帮助深表感谢!!
这是我的代码的第一部分,直到正文,遗憾的是我无法显示其余部分:
<?php
require 'includes/connection.php';
require 'src/facebook.php';
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
'appId' => '~myid~',
'secret' => '~mysecret~',
));
// Get User ID
$user = $facebook->getUser();
// 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');
$access_token = $facebook->getAccessToken();
$user_name = $user_profile[first_name];
/*
echo $user;
echo "<br/><br/>";
echo $access_token;
*/
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}/*elseif($_GET[user]){
$user = $_GET[user];
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
$access_token = $facebook->getAccessToken();
$user_name = $user_profile[first_name];
/*
echo $user;
echo "<br/><br/>";
echo $access_token;
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
}*/
// Login or logout url will be needed depending on current user state.
$logoutUrl = $facebook->getLogoutUrl();
$loginUrl = $facebook->getLoginUrl(array('scope'=>'offline_access'));
//Get youtube video ID from URL
// & Linkify youtube URLs which are not already links.
function linkifyYouTubeURLs($text) {
$text = preg_replace('~
# Match non-linked youtube URL in the wild. (Rev:20111012)
https?:// # Required scheme. Either http or https.
(?:[0-9A-Z-]+\.)? # Optional subdomain.
(?: # Group host alternatives.
youtu\.be/ # Either youtu.be,
| youtube\.com # or youtube.com followed by
\S* # Allow anything up to VIDEO_ID,
[^\w\-\s] # but char before ID is non-ID char.
) # End host alternatives.
([\w\-]{11}) # $1: VIDEO_ID is exactly 11 chars.
(?=[^\w\-]|$) # Assert next char is non-ID or EOS.
(?! # Assert URL is not pre-linked.
[?=&+%\w]* # Allow URL (query) remainder.
(?: # Group pre-linked alternatives.
[\'"][^<>]*> # Either inside a start tag,
| </a> # or inside <a> element text contents.
) # End recognized pre-linked alts.
) # End negative lookahead assertion.
[?=&+%\w]* # Consume any URL (query) remainder.
~ix',
'$1',
$text);
return $text;
}
// function to convert second to time ( minute and secong format)
function secTomin($secs)
{
$sec = $secs % 60;
if($sec < 10)
{
$sec = '0'.$sec;
}
$min = floor($secs/60);
$ret = $min.':'.$sec;
return $ret;
}
//Output Buffering
// make sure output buffering is off before we start it
// this will ensure same effect whether or not ob is enabled already
while (ob_get_level()) {
ob_end_flush();
}
// start output buffering
if (ob_get_length() === false) {
ob_start();
}
//replace accents
function replaceAccentedCharacters($str)
{
$search = explode(",","ç,æ,œ,á,é,í,ó,ú,à,è,ì,ò,ù,ä,ë,ï,ö,ü,ÿ,â,ê,î,ô,û,å,e,i,ø,u");
$replace = explode(",","c,ae,oe,a,e,i,o,u,a,e,i,o,u,a,e,i,o,u,y,a,e,i,o,u,a,e,i,o,u");
$strreplaced = str_replace($search, $replace, $str);
return $strreplaced;
}
?>
<!DOCTYPE>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script src="http://connect.soundcloud.com/sdk.js" type="text/JavaScript"></script>
<script src="togglemenu.js" type="text/JavaScript"></script>
<script type="text/JavaScript">
SC.initialize({
client_id: "~mycliendid~",
redirect_uri: "~myurl~",
});
</script>
<script type="text/javascript" src="ajax.js"></script>
<link type="text/css" rel="stylesheet" href="css/jquery-ui-1.8.9.custom/jquery-ui-1.8.9.custom.css" />
<script type="text/javascript" src="jquery-ui-1.8.13.custom.min.js"></script>
<script type="text/javascript" src="jquery.multi-accordion-1.5.3.js"></script>
<link rel='stylesheet' href='css/lionbars.css' />
<script type="text/javascript" src="jquery.lionbars.0.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#song_list').lionbars({
autohide: true
});
});
</script>
</head>
此代码中的所有 javascript 现在都无法正常工作。此外,我在上面的代码中替换了我的 facebook 和 soundcloud 应用数据。抱歉有点乱。希望我可以发布所有内容,但这不取决于我。提前感谢您的帮助!
这是我要求的 SQL 语句 - 实际上只是我使用相同格式设置的测试语句:
$query = "SELECT * FROM users WHERE fb_user_id = '$user'";
$likes = mysql_query($query);
$num = mysql_num_rows($likes);
echo $num;
while ($like_list = mysql_fetch_array($likes, MYSQL_ASSOC)){
$like = $like_list['fb_from_id'];
echo $like;
}