Bu API, Google arama sonuçlarını belirli bir coğrafi konuma göre özelleştirmenizi sağlar. Bu, farklı konumlardaki Google arama sonuçlarını görüntülemek istediğinizde, yerel SEO çalışmaları yaparken veya farklı bölgelerdeki sonuçları test ederken çok yararlıdır.
API'yi kullanmak için aşağıdaki endpoint'e istek göndermeniz gerekir:
GET https://www.malatyauyducum.com/search/search_api.php?location=POSTA_KODU&query=ARAMA_SORGUSU&country=ÜLKE_KODU
| Parametre | Gerekli | Varsayılan | Açıklama |
|---|---|---|---|
location |
Evet | - | Posta kodu veya yer adı. Arama yapılacak konumu belirtir. |
query |
Evet | - | Google'da aranacak arama sorgusu. |
country |
Hayır | TR | İki harfli ISO ülke kodu (örn. TR, US, DE, UK). |
format |
Hayır | json | Cevap formatı. json veya redirect olabilir. redirect seçilirse, doğrudan arama sonuçlarına yönlendirilirsiniz. |
GET https://www.malatyauyducum.com/search/search_api.php?location=44080&query=pizza&country=TR
GET https://www.malatyauyducum.com/search/search_api.php?location=istanbul&query=hava+durumu&country=TR
GET https://www.malatyauyducum.com/search/search_api.php?location=90210&query=best+restaurants&country=US&format=redirect
API, varsayılan olarak JSON formatında veri döndürür. Örnek yanıt:
{
"success": true,
"search_url": "https://google.com.tr/search?q=pizza&gl=TR&hl=tr&uule=a+CMKC...",
"location": {
"input": "34200",
"resolved": "Istanbul",
"country": "TR",
"latitude": 41.0138,
"longitude": 28.9496
},
"query": "pizza",
"uule": "a+CMKC..."
}
{
"success": false,
"error": "Location not found: 12345 in country: TR"
}
// API'ye istek gönderme
async function searchWithLocation(location, query, country = 'TR') {
try {
const url = `https://www.malatyauyducum.com/search/search_api.php?location=${encodeURIComponent(location)}&query=${encodeURIComponent(query)}&country=${country}`;
const response = await fetch(url);
if (!response.ok) {
throw new Error(`API isteği başarısız: ${response.status}`);
}
const data = await response.json();
if (data.success) {
// Arama URL'sini kullan
window.open(data.search_url, '_blank');
} else {
// Hata mesajını göster
console.error(data.error);
}
} catch (error) {
console.error('İstek hatası:', error);
}
}
// API'ye istek gönderme
function searchWithLocation($location, $query, $country = 'TR') {
$url = "https://www.malatyauyducum.com/search/search_api.php?location=" . urlencode($location) .
"&query=" . urlencode($query) .
"&country=" . $country;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'İstek hatası: ' . curl_error($ch);
return false;
}
curl_close($ch);
$data = json_decode($response, true);
if ($data['success']) {
// Arama URL'sini kullan
header("Location: " . $data['search_url']);
exit;
} else {
// Hata mesajını göster
echo 'API hatası: ' . $data['error'];
}
}