67 lines
2.0 KiB
JavaScript
67 lines
2.0 KiB
JavaScript
const { google } = require('googleapis');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
// KONFIGURATION
|
|
// ==========================================
|
|
// Pfad zu deinem Service Account Key
|
|
const KEY_FILE = path.join(__dirname, '../service_account.json');
|
|
|
|
// Liste der URLs, die du indexieren willst
|
|
const URLS_TO_INDEX = [
|
|
'https://www.qrmaster.net/tools/barcode-generator',
|
|
// Füge hier weitere URLs hinzu
|
|
];
|
|
// ==========================================
|
|
|
|
async function runUsingServiceAccount() {
|
|
if (!fs.existsSync(KEY_FILE)) {
|
|
console.error('❌ FEHLER: service_account.json nicht gefunden!');
|
|
console.error(' Bitte befolge die Anleitung in INDEXING_GUIDE.md und speichere den Key im Hauptordner.');
|
|
return;
|
|
}
|
|
|
|
console.log(`🔑 Authentifiziere mit Key-File: ${KEY_FILE}...`);
|
|
|
|
const auth = new google.auth.GoogleAuth({
|
|
keyFile: KEY_FILE,
|
|
scopes: ['https://www.googleapis.com/auth/indexing'],
|
|
});
|
|
|
|
const client = await auth.getClient();
|
|
|
|
// console.log(`🔑 Authentifiziere als: ${key.client_email}...`);
|
|
|
|
try {
|
|
// await jwtClient.authorize(); // Nicht mehr nötig mit GoogleAuth
|
|
console.log('✅ Authentifizierung erfolgreich.');
|
|
|
|
for (const url of URLS_TO_INDEX) {
|
|
console.log(`🚀 Sende Indexierungs-Anfrage für: ${url}`);
|
|
|
|
const result = await google.indexing('v3').urlNotifications.publish({
|
|
auth: client,
|
|
requestBody: {
|
|
url: url,
|
|
type: 'URL_UPDATED'
|
|
}
|
|
});
|
|
|
|
console.log(` Status: ${result.status} ${result.statusText}`);
|
|
console.log(` Server Antwort:`, result.data);
|
|
}
|
|
|
|
console.log('\n✨ Fertig! Google wurde benachrichtigt.');
|
|
console.log(' Hinweis: Es kann immer noch ein paar Stunden dauern, bis Änderungen sichtbar sind.');
|
|
|
|
} catch (error) {
|
|
console.error('\n❌ Es ist ein Fehler aufgetreten:');
|
|
console.error(error.message);
|
|
if (error.response) {
|
|
console.error('Details:', error.response.data);
|
|
}
|
|
}
|
|
}
|
|
|
|
runUsingServiceAccount();
|