如何使用Facebook Marketing API有效地获取给定广告帐户的所有被拒登广告的ID?
理想情况是:
GET /act_1231423423423/ads?effective_status=DISAPPROVED&fields=ad_review_feedback
但是FB不支持这样的查询
我不想获取所有广告,因为我有很多广告。
答案 0 :(得分:0)
使用
<?php
/**
* Fetch remote image and send to client
*/
// Remote URL from which to fetch images
$remoteBaseUrl = 'https://example.com/ad-image/ads/1234/';
// Permitted file extensions / mime-types
// NB: If using CURL, can get the mime-type from the HTTP response instead
$mimeTypes = [
'gif' => 'image/gif',
'jpg' => 'image/jpeg',
'png' => 'image/png',
'webp' => 'image/webp',
];
// Get the reqd file the "file" URL parameter in the rewritten URL
$file = $_GET['file'] ?? null;
$remoteUrl = null;
// Validate filename format
// Or even check against a known list of files?
$filenameRegex = '/^[\w-]+\.('.implode('|',array_keys($mimeTypes)).')$/';
if (preg_match($filenameRegex, $file, $matches)) {
header('Content-Type: '.$mimeTypes[$matches[1]]);
$remoteUrl = $remoteBaseUrl.$file;
// OPTIONAL: Check cache here...
// readfile() and exit if current.
// Using readfile()
// - simple, but does not provide any error handling on the HTTP response
// eg. if the remote file does not exist etc.
//$bytes = readfile($remoteUrl);
//if ($bytes === false) {
// General 500 Internal Server Error
// http_response_code(500);
//} else {
// // No error - assume success!
// // But there could have been an HTTP response "error" that is lost
//}
//exit;
// Using CURL
$ch = curl_init($remoteUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$content = curl_exec($ch);
$curlError = curl_errno($ch);
if ($curlError) $curlError .= ': '.curl_error($ch);
$httpStatus = curl_getinfo($ch,CURLINFO_RESPONSE_CODE);
curl_close($ch);
if ($curlError) {
// Only set header when debugging, otherwise could expose the target URL
//header('X-CURL-ERROR: '.$curlError);
// General 500 Internal Server Error
http_response_code(500);
}
// CURL request is OK, but could still be an HTTP failure...
else {
// OK - serve image
if ($httpStatus === 200) {
// OPTIONAL: Save to cache...
echo $content;
}
// Pass through HTTP status from CURL request... 404, 403, etc...
else {
http_response_code($httpStatus);
}
}
exit;
}
// Default failure... "Bad Request"
http_response_code(400);