当我第一次登陆包含以下代码的页面(此后读取:connect_callback.php)时,将从会话中检索并显示正确的电子邮件。但是当从soundcloud页面将呼叫返回到页面时,电子邮件显示为NULL。我需要电子邮件ID将相关数据插入数据库。我无法找到解决这个问题的方法。
<?php
require_once 'lib/Soundcloud.php';
session_start();
$email = $_SESSION[`email`];
//var_dump($email);
$clientId = "XXXXXXXXXXXX";
$clientSecret = "XXXXXXXXXXXX";
$callback = "XXXXXXXXX";
$soundcloud = new Services_SoundCloud($clientId,$clientSecret,$callback);
$soundcloud->setDevelopment(false);
$authURL = $soundcloud->getAuthorizeUrl();
//echo "<pre>";
echo "<a href='$authURL'>Connect to SoundCloud</a>";
//Attempt tp get token from Session First
//Set the token otherwise...
try{
if (!isset($_SESSION['token'])){
$accessToken = $soundcloud->accessToken($_GET['code']);
$_SESSION['token'] = $accessToken['access_token'];
}
else{
$soundcloud->setAccessToken($_SESSION['token']);
}
}
catch(Services_Soundcloud_Invalid_Http_Response_Code_Exception $e){
exit($e->getMessage());
}
try{
$me = json_decode($soundcloud->get('me'), true);
//print_r($me);
$user_data = array(
'access_token' => $accessToken['access_token'],
'id' => $me['id']
);
$tracks = json_decode($soundcloud->get('tracks', array('user_id' => $user_data['id'])), true);
//print_r($tracks);
$htmlBody .= '<h3>Your Track List</h3><form action="upload_soundcloudlinks.php" method="POST"><input type="hidden" name="email" value="'.$email.'" />';
foreach($tracks as $track){
/*echo $track['permalink_url'];
$song = $track['permalink_url'];*/
$htmlBody .= sprintf('<input type="checkbox" name="soundcloud[]" value="%s">%s<br>', $track['permalink_url'],$track['title']);
}
$htmlBody .= '<input type="submit" value="Upload These" /></form>';
/*$user_tracks = array(
'link' => $tracks['permalink_url'];
);
print_r($tracks['permalink_url']);*/
}
catch(Services_Soundcloud_Invalid_Http_Response_Code_Exception $e){
exit($e->getMessage());
}
?>
<!doctype html>
<html>
<head>
<title>My Uploads</title>
</head>
<body>
<?=$htmlBody?>
</body>
</html>
答案 0 :(得分:0)
在您使用$ _GET的html体中,您应该使用相同的$ email变量或从$ _SESSION设置它。