clientId . ':' . $this->clientSecret);
$headers = [
'Content-Type: application/x-www-form-urlencoded',
'Authorization: Basic ' . $credentials
];
$data = http_build_query([
'grant_type' => 'client_credentials',
'scope' => $this->scope
]);
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $data,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_VERBOSE => true
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (curl_errno($ch)) {
error_log('eBay Auth cURL Error: ' . curl_error($ch));
return ['error' => 'Connection error: ' . curl_error($ch)];
}
curl_close($ch);
$decoded = json_decode($response, true);
if (!$decoded && json_last_error() !== JSON_ERROR_NONE) {
error_log('eBay Auth Response: ' . $response);
return ['error' => 'Invalid response format'];
}
if ($httpCode !== 200) {
error_log('eBay Auth Error Response: ' . print_r($decoded, true));
return ['error' => 'API Error: ' . ($decoded['error_description'] ?? $decoded['error'] ?? 'Unknown error')];
}
return $decoded;
}
}
// Get new access token
$auth = new EbayAuth();
$token_response = $auth->getApplicationToken();
if (isset($token_response['error'])) {
echo '
Failed to get eBay API access token: ' . htmlspecialchars($token_response['error']) . '
';
return;
} elseif (!isset($token_response['access_token'])) {
echo 'Failed to get eBay API access token: Invalid response format
';
error_log("eBay Auth Error: " . print_r($token_response, true));
return;
}
// Add eBay Affiliate Configuration after eBay API Configuration
$ebay_app_id = 'YOUR DATA';
$ebay_campaign_id = 'YOUR DATA'; // Add your EPN Campaign ID
$ebay_affiliate_id = 'YOUR DATA'; // Add your EPN Affiliate ID
$endpoint = 'https://api.ebay.com/buy/browse/v1/item_summary/search';
// Search Parameters
$keywords = isset($_GET['keywords']) ? $_GET['keywords'] : '';
$sort = isset($_GET['sort']) ? $_GET['sort'] : 'endingSoonest';
$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
$limit = 20;
// Update headers with new access token
$headers = [
'Authorization: Bearer ' . $token_response['access_token'],
'X-EBAY-C-MARKETPLACE-ID: EBAY-US',
'Content-Type: application/json'
];
// API Request
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $endpoint . "?q=" . urlencode($keywords) .
"&sort=" . $sort .
"&fieldgroups=BUYING_OPTIONS_PRICES" .
"&limit=" . $limit .
"&offset=" . (($page-1) * $limit) .
"&filter=buyingOptions:{AUCTION|FIXED_PRICE}" .
"&filter=itemLocation.country:US",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_SSL_VERIFYPEER => false, // SSL 검증 비활성화
CURLOPT_VERBOSE => true // 상세 디버깅 정보 활성화
]);
$response = curl_exec($ch);
// Add error handling
if ($response === false) {
echo "cURL Error: " . curl_error($ch);
$info = curl_getinfo($ch);
echo "Debug info: " . print_r($info, true) . "
";
} else {
$data = json_decode($response, true);
if (json_last_error() !== JSON_ERROR_NONE) {
echo "JSON Error: " . json_last_error_msg();
echo "
Raw Response: " . htmlspecialchars(substr($response, 0, 1000));
}
}
$data = json_decode($response, true);
curl_close($ch);
// Search Form
?>
마감임박순은 마감일이 가까운 순으로 검색합니다.
최신등록순은 최근에 등록된 상품을 검색합니다.
모든 상품 검색은 US 지역안으로 제한됩니다.
검색어는 영어로 검색하시면 더 정확한 결과를 얻을 수 있습니다. (한글 검색도 가능)
입찰하기 버튼은 현재 진행중인 eBay 경매나 옥션을, 구매하기 버튼은 eBay 쇼핑을 의미합니다.
';
foreach ($data['itemSummaries'] as $item) {
?>
현재가: $
현재 입찰가: $
0) { ?>
입찰수:
diff($endDate);
if ($interval->invert == 0) { // If the end date is in the future
$timeLeft = '';
if ($interval->d > 0) $timeLeft .= $interval->d . '일 ';
if ($interval->h > 0) $timeLeft .= $interval->h . '시간 ';
if ($interval->i > 0) $timeLeft .= $interval->i . '분 ';
echo '
남은시간: ' . $timeLeft . '
';
}
}
?>
';
// Pagination
if (isset($data['total'])) {
$total_pages = ceil($data['total'] / $limit);
echo '';
}
}
?>