curl \
-H "Authorization: Bearer API_KEY" \
-X GET https://api.ayrshare.com/api/ads/facebook/accounts
const API_KEY = "API_KEY";
fetch("https://api.ayrshare.com/api/ads/facebook/accounts", {
method: "GET",
headers: {
"Authorization": `Bearer ${API_KEY}`
}
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
import requests
headers = {'Authorization': 'Bearer API_KEY'}
r = requests.get('https://api.ayrshare.com/api/ads/facebook/accounts', headers=headers)
print(r.json())
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.ayrshare.com/api/ads/facebook/accounts",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer API_KEY"
]
]);
$response = curl_exec($curl);
curl_close($curl);
echo $response;
?>
using System;
using System.Net.Http;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
string apiKey = "API_KEY";
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiKey}");
HttpResponseMessage response = await client.GetAsync("https://api.ayrshare.com/api/ads/facebook/accounts");
string content = await response.Content.ReadAsStringAsync();
Console.WriteLine(content);
}
}
}
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
apiKey := "API_KEY"
req, _ := http.NewRequest("GET", "https://api.ayrshare.com/api/ads/facebook/accounts", nil)
req.Header.Add("Authorization", "Bearer " + apiKey)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
}
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class GetAdAccounts {
public static void main(String[] args) {
try {
String apiKey = "API_KEY";
URL url = new URL("https://api.ayrshare.com/api/ads/facebook/accounts");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Authorization", "Bearer " + apiKey);
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println(response.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
require 'net/http'
require 'json'
uri = URI('https://api.ayrshare.com/api/ads/facebook/accounts')
req = Net::HTTP::Get.new(uri)
req['Authorization'] = 'Bearer API_KEY'
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http|
http.request(req)
}
puts response.body
{
"status": "success",
"adAccounts": [
{
"accountId": "274948345",
"ageInDays": 2870.86,
"amountSpent": 191.33,
"balance": 7.84,
"budgetRemaining": 1,
"business": {
"name": "Fun Fun Fun",
"city": "New York",
"country": "US",
"state": "NY",
"street": "178 Columbus Ave",
"zip": "10023"
},
"created": "2012-01-05T03:11:31-0800",
"currency": "USD",
"disableReason": null,
"fundingSource": {
"id": "13157487252022",
"type": "Credit Card"
},
"hasNotificationsEnabled": true,
"isPersonal": false,
"isPrepayAccount": false,
"metrics": {
"spend": 191.33,
"impressions": 24994,
"reach": 20410,
"clicks": 622,
"ctr": 2.488597,
"cpm": 7.655037,
"cpp": 9.374326,
"frequency": 1.224596,
"uniqueClicks": 432,
"uniqueCtr": 2.11661,
"costPerUniqueClick": 0.442894,
"inlineLinkClicks": 538,
"costPerInlineLinkClick": 0.355632,
"outboundClicks": 468,
"costPerOutboundClick": 0.408825,
"websiteCtr": [
{
"action_type": "link_click",
"value": "2.152517"
}
],
"accountCurrency": "USD",
"accountName": "John Smith",
"accountId": "274948321"
},
"minDailyBudget": 1,
"name": "John Smith",
"owner": "3205611418413",
"spendCap": 0,
"status": "Active",
"tax": {
"id": "824087134",
"type": "Business Tax ID (EIN/SSN)",
"status": "Pending",
"isRequired": false
},
"timezoneName": "America/Los_Angeles",
"tosAccepted": {
"webCustomAudienceTos": true,
"customAudienceTos": true
}
}
],
"count": 1,
"lastUpdated": "2025-03-26T19:33:51.571Z",
"nextUpdate": "2025-03-26T19:44:51.571Z",
"meta": { "pagination": { "hasMore": false } }
}
{
"action": "get ad accounts",
"status": "error",
"code": 366,
"message": "Error getting ad accounts. Please verify you have an active Meta ad account and have granted permission to access it. Try unlinking and relinking the platform, then try again. Contact us if the issue persists."
}
Facebook Ads
Contas
Liste as contas de anúncios do Facebook vinculadas ao perfil autenticado, com status, métricas de desempenho agregadas e resultados em cache por 10 minutos.
GET
/
ads
/
facebook
/
accounts
curl \
-H "Authorization: Bearer API_KEY" \
-X GET https://api.ayrshare.com/api/ads/facebook/accounts
const API_KEY = "API_KEY";
fetch("https://api.ayrshare.com/api/ads/facebook/accounts", {
method: "GET",
headers: {
"Authorization": `Bearer ${API_KEY}`
}
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
import requests
headers = {'Authorization': 'Bearer API_KEY'}
r = requests.get('https://api.ayrshare.com/api/ads/facebook/accounts', headers=headers)
print(r.json())
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.ayrshare.com/api/ads/facebook/accounts",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer API_KEY"
]
]);
$response = curl_exec($curl);
curl_close($curl);
echo $response;
?>
using System;
using System.Net.Http;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
string apiKey = "API_KEY";
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiKey}");
HttpResponseMessage response = await client.GetAsync("https://api.ayrshare.com/api/ads/facebook/accounts");
string content = await response.Content.ReadAsStringAsync();
Console.WriteLine(content);
}
}
}
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
apiKey := "API_KEY"
req, _ := http.NewRequest("GET", "https://api.ayrshare.com/api/ads/facebook/accounts", nil)
req.Header.Add("Authorization", "Bearer " + apiKey)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
}
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class GetAdAccounts {
public static void main(String[] args) {
try {
String apiKey = "API_KEY";
URL url = new URL("https://api.ayrshare.com/api/ads/facebook/accounts");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Authorization", "Bearer " + apiKey);
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println(response.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
require 'net/http'
require 'json'
uri = URI('https://api.ayrshare.com/api/ads/facebook/accounts')
req = Net::HTTP::Get.new(uri)
req['Authorization'] = 'Bearer API_KEY'
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http|
http.request(req)
}
puts response.body
{
"status": "success",
"adAccounts": [
{
"accountId": "274948345",
"ageInDays": 2870.86,
"amountSpent": 191.33,
"balance": 7.84,
"budgetRemaining": 1,
"business": {
"name": "Fun Fun Fun",
"city": "New York",
"country": "US",
"state": "NY",
"street": "178 Columbus Ave",
"zip": "10023"
},
"created": "2012-01-05T03:11:31-0800",
"currency": "USD",
"disableReason": null,
"fundingSource": {
"id": "13157487252022",
"type": "Credit Card"
},
"hasNotificationsEnabled": true,
"isPersonal": false,
"isPrepayAccount": false,
"metrics": {
"spend": 191.33,
"impressions": 24994,
"reach": 20410,
"clicks": 622,
"ctr": 2.488597,
"cpm": 7.655037,
"cpp": 9.374326,
"frequency": 1.224596,
"uniqueClicks": 432,
"uniqueCtr": 2.11661,
"costPerUniqueClick": 0.442894,
"inlineLinkClicks": 538,
"costPerInlineLinkClick": 0.355632,
"outboundClicks": 468,
"costPerOutboundClick": 0.408825,
"websiteCtr": [
{
"action_type": "link_click",
"value": "2.152517"
}
],
"accountCurrency": "USD",
"accountName": "John Smith",
"accountId": "274948321"
},
"minDailyBudget": 1,
"name": "John Smith",
"owner": "3205611418413",
"spendCap": 0,
"status": "Active",
"tax": {
"id": "824087134",
"type": "Business Tax ID (EIN/SSN)",
"status": "Pending",
"isRequired": false
},
"timezoneName": "America/Los_Angeles",
"tosAccepted": {
"webCustomAudienceTos": true,
"customAudienceTos": true
}
}
],
"count": 1,
"lastUpdated": "2025-03-26T19:33:51.571Z",
"nextUpdate": "2025-03-26T19:44:51.571Z",
"meta": { "pagination": { "hasMore": false } }
}
{
"action": "get ad accounts",
"status": "error",
"code": 366,
"message": "Error getting ad accounts. Please verify you have an active Meta ad account and have granted permission to access it. Try unlinking and relinking the platform, then try again. Contact us if the issue persists."
}
Recupere as contas de anúncios do Facebook disponíveis associadas ao perfil autenticado.
Este endpoint permite acessar informações básicas da conta, bem como métricas-chave das contas de anúncios.
- O objeto
metricscontém dados agregados de desempenho de todos os anúncios da conta - Os resultados são armazenados em cache por 10 minutos para otimizar o desempenho e reduzir as chamadas de API ao Facebook
- O status da conta na resposta JSON pode ser um dos seguintes:
active,disabled,unsettled,pending reviewouclosed
Parâmetros de cabeçalho
Parâmetros de consulta
Quando a resposta tiver
meta.pagination.hasMore: true, envie aqui o valor meta.pagination.next dela para obter a próxima página. Envie os outros parâmetros sem alterações: um valor next de outra solicitação retorna code: 101.curl \
-H "Authorization: Bearer API_KEY" \
-X GET https://api.ayrshare.com/api/ads/facebook/accounts
const API_KEY = "API_KEY";
fetch("https://api.ayrshare.com/api/ads/facebook/accounts", {
method: "GET",
headers: {
"Authorization": `Bearer ${API_KEY}`
}
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
import requests
headers = {'Authorization': 'Bearer API_KEY'}
r = requests.get('https://api.ayrshare.com/api/ads/facebook/accounts', headers=headers)
print(r.json())
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.ayrshare.com/api/ads/facebook/accounts",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer API_KEY"
]
]);
$response = curl_exec($curl);
curl_close($curl);
echo $response;
?>
using System;
using System.Net.Http;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
string apiKey = "API_KEY";
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiKey}");
HttpResponseMessage response = await client.GetAsync("https://api.ayrshare.com/api/ads/facebook/accounts");
string content = await response.Content.ReadAsStringAsync();
Console.WriteLine(content);
}
}
}
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
apiKey := "API_KEY"
req, _ := http.NewRequest("GET", "https://api.ayrshare.com/api/ads/facebook/accounts", nil)
req.Header.Add("Authorization", "Bearer " + apiKey)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
}
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class GetAdAccounts {
public static void main(String[] args) {
try {
String apiKey = "API_KEY";
URL url = new URL("https://api.ayrshare.com/api/ads/facebook/accounts");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Authorization", "Bearer " + apiKey);
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println(response.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
require 'net/http'
require 'json'
uri = URI('https://api.ayrshare.com/api/ads/facebook/accounts')
req = Net::HTTP::Get.new(uri)
req['Authorization'] = 'Bearer API_KEY'
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http|
http.request(req)
}
puts response.body
{
"status": "success",
"adAccounts": [
{
"accountId": "274948345",
"ageInDays": 2870.86,
"amountSpent": 191.33,
"balance": 7.84,
"budgetRemaining": 1,
"business": {
"name": "Fun Fun Fun",
"city": "New York",
"country": "US",
"state": "NY",
"street": "178 Columbus Ave",
"zip": "10023"
},
"created": "2012-01-05T03:11:31-0800",
"currency": "USD",
"disableReason": null,
"fundingSource": {
"id": "13157487252022",
"type": "Credit Card"
},
"hasNotificationsEnabled": true,
"isPersonal": false,
"isPrepayAccount": false,
"metrics": {
"spend": 191.33,
"impressions": 24994,
"reach": 20410,
"clicks": 622,
"ctr": 2.488597,
"cpm": 7.655037,
"cpp": 9.374326,
"frequency": 1.224596,
"uniqueClicks": 432,
"uniqueCtr": 2.11661,
"costPerUniqueClick": 0.442894,
"inlineLinkClicks": 538,
"costPerInlineLinkClick": 0.355632,
"outboundClicks": 468,
"costPerOutboundClick": 0.408825,
"websiteCtr": [
{
"action_type": "link_click",
"value": "2.152517"
}
],
"accountCurrency": "USD",
"accountName": "John Smith",
"accountId": "274948321"
},
"minDailyBudget": 1,
"name": "John Smith",
"owner": "3205611418413",
"spendCap": 0,
"status": "Active",
"tax": {
"id": "824087134",
"type": "Business Tax ID (EIN/SSN)",
"status": "Pending",
"isRequired": false
},
"timezoneName": "America/Los_Angeles",
"tosAccepted": {
"webCustomAudienceTos": true,
"customAudienceTos": true
}
}
],
"count": 1,
"lastUpdated": "2025-03-26T19:33:51.571Z",
"nextUpdate": "2025-03-26T19:44:51.571Z",
"meta": { "pagination": { "hasMore": false } }
}
{
"action": "get ad accounts",
"status": "error",
"code": 366,
"message": "Error getting ad accounts. Please verify you have an active Meta ad account and have granted permission to access it. Try unlinking and relinking the platform, then try again. Contact us if the issue persists."
}