How to Scrape LinkedIn Ad Library Ad Details with Go
Get details for a specific LinkedIn ad using Go. This comprehensive guide will walk you through the entire process, from setup to implementation.
Overview
What You'll Learn
- Setting up your Go environment
- Installing the required HTTP client
- Authenticating with SociaVault API
- Making requests to LinkedIn Ad Library
- Handling responses and errors
What You'll Get
- Access to ad details data
- JSON formatted responses
- Real-time data access
- Scalable solution
- Error handling patterns
Prerequisites
1. API Key
First, you'll need a SociaVault API key to authenticate your requests.
2. Development Environment
Make sure you have the following installed:
- Go installed
- A code editor (VS Code, Sublime, etc.)
- Command line interface access
Implementation
Step 1: Install HTTP Client
We'll use net/http to make HTTP requests.
// Standard libraryStep 2: API Implementation
Now let's make a request to the LinkedIn Ad Library API using Go. Replace YOUR_API_KEY with your actual API key.
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
url := "https://api.sociavault.com/linkedin-ad-library/ad-details?url=https%3A%2F%2Fwww.linkedin.com%2Fad-library%2F..."
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("x-api-key", "YOUR_API_KEY")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(string(body))
}Testing Your Code
API Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| url | string | Yes | Example: https://www.linkedin.com/ad-library/... |
Expected Response
You should receive a structured JSON response containing the ad details data.
{
"success": true,
"id": "664291126",
"description": "Learn to start building an AI strategy that helps your small business automate routine tasks and keep teams focused on high-value activities.",
"headline": "Read “The Guide to AI for Small Businesses”",
"poster": "Salesforce",
"posterTitle": "Promoted",
"targeting": {
"language": "Targeting includes English",
"location": "Targeting includes Portugal",
"audience": "Inclusion and exclusion targeting applied"
},
"image": "https://media.licdn.com/dms/image/v2/D5610AQHEjQAydHWLaw/image-shrink_1280/image-shrink_1280/0/1736950502005/Ai-guide-for-smbs?e=2147483647&v=beta&t=dC-iPz1fr8piN6YutdDgKIOmRPJvFaj4Hr0g_raHZ70",
"adType": "Single Image Ad",
"advertiser": "Salesforce",
"advertiserLinkedinPage": "https://www.linkedin.com/company/3185",
"destinationUrl": "https://www.salesforce.com/eu/form/small-business/ai-guide-for-smbs/?d=701ed00000CX0GfAAL&nc=701ed000007UYTMAA4&utm_source=linkedin&utm_medium=paid_social&utm_campaign=emea_pt_einsteinai_allindustries&utm_content=enterprisesmallbusiness_pp-dm-all-crx-multi-tal-linkedin-prospect-tals-esmb_701ed00000CX0GfAAL_english_ai-guide-for-smbs&trk=ad_library_ad_preview_headline_content",
"adDuration": "Ran from Apr 1, 2025 to Apr 3, 2025",
"startDate": "2025-04-01T00:00:00.000Z",
"endDate": "2025-04-03T00:00:00.000Z",
"totalImpressions": "5k-10k",
"impressionsByCountry": [
{
"country": "Portugal",
"impressions": "100%"
}
]
}Best Practices
Error Handling
Implement comprehensive error handling and retry logic for failed requests. Log errors properly for debugging.
Caching
Cache responses when possible to reduce API calls and improve performance. Consider data freshness requirements.
Security
Never expose your API key in client-side code. Use environment variables and secure key management practices.
Troubleshooting
Unauthorized
Check your API key is correct and properly formatted in the x-api-key header.
Payment Required
You ran out of credits and need to buy more.
Not Found
The resource (user, video, etc.) might not exist or be private.
Too Many Requests
You have exceeded your rate limit. Slow down your requests.
Frequently Asked Questions
How much does it cost to scrape LinkedIn Ad Library?
SociaVault offers 50 free API calls to get started. After that, pricing starts at $10 for 5k requests with volume discounts available.
Is it legal to scrape LinkedIn Ad Library data?
Scraping publicly available data is generally considered legal. We only collect public data that is accessible without logging in.
How fast can I scrape LinkedIn Ad Library?
Our API handles the rate limiting for you. You can make requests as fast as your plan allows.
What data format does the API return?
All API responses are returned in JSON format, making it easy to integrate with any programming language or application.
Related Tutorials
Ad Details in Other Languages
Ad Details with Node.jsAd Details with JavaScriptAd Details with PythonAd Details with PHPReady to Start Scraping?
Get started with 50 free API calls. No credit card required. Stop worrying about proxies and captchas.