curl \
-H "Authorization: Bearer API_KEY" \
-X GET "https://api.ayrshare.com/api/ads/google/accounts"
const API_KEY = "API_KEY";
fetch("https://api.ayrshare.com/api/ads/google/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/google/accounts", headers=headers)
print(r.json())
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.ayrshare.com/api/ads/google/accounts",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer API_KEY"
]
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error: " . $err;
} else {
echo $response;
}
?>
using System;
using System.Net.Http;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", "Bearer API_KEY");
var response = await client.GetAsync("https://api.ayrshare.com/api/ads/google/accounts");
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine(content);
}
}
package main
import (
"fmt"
"io"
"net/http"
)
func main() {
req, _ := http.NewRequest("GET", "https://api.ayrshare.com/api/ads/google/accounts", nil)
req.Header.Add("Authorization", "Bearer API_KEY")
resp, err := http.DefaultClient.Do(req)
if err != nil {
fmt.Println("Error:", err)
return
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class GetAdAccounts {
public static void main(String[] args) throws Exception {
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.ayrshare.com/api/ads/google/accounts"))
.header("Authorization", "Bearer API_KEY")
.GET()
.build();
HttpResponse<String> response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
require 'net/http'
require 'uri'
uri = URI.parse('https://api.ayrshare.com/api/ads/google/accounts')
request = Net::HTTP::Get.new(uri)
request['Authorization'] = 'Bearer API_KEY'
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
http.request(request)
end
puts response.body
{
"status": "success",
"adAccounts": [{ "id": "1234567890", "name": "Acme", "currency": "USD" }],
"nextCursor": null,
"unavailableAccounts": [{ "id": "2345678901", "reason": "notEnabled" }]
}
Google Ads
Tài khoản
Liệt kê các tài khoản Google Ads mà bạn có thể tạo chiến dịch, và xem những tài khoản đã liên kết nào Google không cho mở cùng lý do.
GET
/
ads
/
google
/
accounts
curl \
-H "Authorization: Bearer API_KEY" \
-X GET "https://api.ayrshare.com/api/ads/google/accounts"
const API_KEY = "API_KEY";
fetch("https://api.ayrshare.com/api/ads/google/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/google/accounts", headers=headers)
print(r.json())
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.ayrshare.com/api/ads/google/accounts",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer API_KEY"
]
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error: " . $err;
} else {
echo $response;
}
?>
using System;
using System.Net.Http;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", "Bearer API_KEY");
var response = await client.GetAsync("https://api.ayrshare.com/api/ads/google/accounts");
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine(content);
}
}
package main
import (
"fmt"
"io"
"net/http"
)
func main() {
req, _ := http.NewRequest("GET", "https://api.ayrshare.com/api/ads/google/accounts", nil)
req.Header.Add("Authorization", "Bearer API_KEY")
resp, err := http.DefaultClient.Do(req)
if err != nil {
fmt.Println("Error:", err)
return
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class GetAdAccounts {
public static void main(String[] args) throws Exception {
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.ayrshare.com/api/ads/google/accounts"))
.header("Authorization", "Bearer API_KEY")
.GET()
.build();
HttpResponse<String> response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
require 'net/http'
require 'uri'
uri = URI.parse('https://api.ayrshare.com/api/ads/google/accounts')
request = Net::HTTP::Get.new(uri)
request['Authorization'] = 'Bearer API_KEY'
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
http.request(request)
end
puts response.body
{
"status": "success",
"adAccounts": [{ "id": "1234567890", "name": "Acme", "currency": "USD" }],
"nextCursor": null,
"unavailableAccounts": [{ "id": "2345678901", "reason": "notEnabled" }]
}
Lấy các tài khoản Google Ads mà bạn có thể tạo chiến dịch. Hãy dùng
id của tài khoản làm accountId khi bạn tạo chiến dịch.
- Trước tiên, hãy liên kết Google Ads từ trang “Social Accounts”.
- Người dùng Google mà bạn liên kết phải có quyền truy cập trực tiếp vào tài khoản quảng cáo. Các tài khoản bạn chỉ truy cập được thông qua một tài khoản người quản lý sẽ không được liệt kê và hiện chưa thể sử dụng: hãy thêm người dùng đó vào chính tài khoản quảng cáo. Các tài khoản người quản lý cũng không được liệt kê: chúng không thể chứa chiến dịch.
- Mọi tài khoản được trả về trong một phản hồi duy nhất, vì vậy
nextCursorluôn lànull.
Tham số Header
Phản hồi
adAccounts liệt kê các tài khoản bạn có thể dùng, kèm id, name và currency của từng tài khoản.
Nếu Google liệt kê một tài khoản nhưng không cho mở tài khoản đó, phản hồi còn có thêm unavailableAccounts. Mỗi mục có id của tài khoản và một reason. Trường này không xuất hiện khi mọi tài khoản đều dùng được.
reason | Ý nghĩa | Cần làm gì |
|---|---|---|
notEnabled | Tài khoản đã bị hủy, bị tạm ngưng hoặc chưa được thiết lập. | Hoàn tất thiết lập hoặc kích hoạt lại tài khoản trong Google Ads, rồi liệt kê lại các tài khoản. Thay đổi có thể mất khoảng 10 phút để hiển thị. |
noAccess | Người dùng Google mà bạn liên kết có thể thấy tài khoản nhưng không có quyền truy cập dữ liệu của tài khoản đó. | Cấp cho người dùng đó quyền truy cập tài khoản quảng cáo trong Google Ads, rồi liệt kê lại các tài khoản. Thay đổi có thể mất khoảng 10 phút để hiển thị. |
curl \
-H "Authorization: Bearer API_KEY" \
-X GET "https://api.ayrshare.com/api/ads/google/accounts"
const API_KEY = "API_KEY";
fetch("https://api.ayrshare.com/api/ads/google/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/google/accounts", headers=headers)
print(r.json())
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.ayrshare.com/api/ads/google/accounts",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer API_KEY"
]
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error: " . $err;
} else {
echo $response;
}
?>
using System;
using System.Net.Http;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", "Bearer API_KEY");
var response = await client.GetAsync("https://api.ayrshare.com/api/ads/google/accounts");
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine(content);
}
}
package main
import (
"fmt"
"io"
"net/http"
)
func main() {
req, _ := http.NewRequest("GET", "https://api.ayrshare.com/api/ads/google/accounts", nil)
req.Header.Add("Authorization", "Bearer API_KEY")
resp, err := http.DefaultClient.Do(req)
if err != nil {
fmt.Println("Error:", err)
return
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class GetAdAccounts {
public static void main(String[] args) throws Exception {
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.ayrshare.com/api/ads/google/accounts"))
.header("Authorization", "Bearer API_KEY")
.GET()
.build();
HttpResponse<String> response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}
require 'net/http'
require 'uri'
uri = URI.parse('https://api.ayrshare.com/api/ads/google/accounts')
request = Net::HTTP::Get.new(uri)
request['Authorization'] = 'Bearer API_KEY'
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
http.request(request)
end
puts response.body
{
"status": "success",
"adAccounts": [{ "id": "1234567890", "name": "Acme", "currency": "USD" }],
"nextCursor": null,
"unavailableAccounts": [{ "id": "2345678901", "reason": "notEnabled" }]
}