fix: paginar asset_group_asset de Google para no perder vídeos/imágenes
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -146,17 +146,32 @@ async function searchGoogle(
|
|||||||
];
|
];
|
||||||
let lastErr = '';
|
let lastErr = '';
|
||||||
for (const headers of attempts) {
|
for (const headers of attempts) {
|
||||||
|
const out: GaqlRow[] = [];
|
||||||
|
let pageToken: string | undefined;
|
||||||
|
let ok = false;
|
||||||
|
for (let page = 0; page < 20; page++) {
|
||||||
|
const body: { query: string; pageToken?: string } = { query };
|
||||||
|
if (pageToken) body.pageToken = pageToken;
|
||||||
const r = await fetch(`${GADS_API}/customers/${cid}/googleAds:search`, {
|
const r = await fetch(`${GADS_API}/customers/${cid}/googleAds:search`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers,
|
headers,
|
||||||
body: JSON.stringify({ query }),
|
body: JSON.stringify(body),
|
||||||
cache: 'no-store',
|
cache: 'no-store',
|
||||||
});
|
});
|
||||||
if (r.ok) {
|
if (!r.ok) {
|
||||||
const j = (await r.json()) as { results?: GaqlRow[] };
|
|
||||||
return j.results || [];
|
|
||||||
}
|
|
||||||
lastErr = await r.text();
|
lastErr = await r.text();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ok = true;
|
||||||
|
const j = (await r.json()) as {
|
||||||
|
results?: GaqlRow[];
|
||||||
|
nextPageToken?: string;
|
||||||
|
};
|
||||||
|
out.push(...(j.results || []));
|
||||||
|
pageToken = j.nextPageToken;
|
||||||
|
if (!pageToken) break;
|
||||||
|
}
|
||||||
|
if (ok) return out;
|
||||||
}
|
}
|
||||||
throw new Error(`Google Ads ${cid}: ${lastErr.slice(0, 220)}`);
|
throw new Error(`Google Ads ${cid}: ${lastErr.slice(0, 220)}`);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user