Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/3dsinteractive/facebook-marketing-api-golang-sdk

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/3dsinteractive/facebook-marketing-api-golang-sdk

  • v0.0.0-20240711054757-7282091495fe
  • Source
  • Go
  • Socket score

Version published
Created
Source

Facebook Marketing API SDK for Golang

Go Report Card

This go package provides a comprehensive list of methods for interacting with Facebook's Graph Marketing api.


JustWatch logo

You enjoy working with the Facebook Marketing API? We are hiring!

Find out what open positions we have at the moment and why JustWatch is a great place to work at: https://www.justwatch.com/us/talent


The SDK supports crud operations for the following entities:

  • ad_account
  • adset
  • custom_conversion
  • insights
  • post
  • videos
  • adcreative
  • audience
  • event
  • interest
  • search
  • ads
  • campaign
  • image
  • page
  • service

Usage

We assume you already have a Facebook Developer account and configured an accessToken and appSecret. If not, checkout Facebooks Get Started

Create a new fbService client

import(
	"github.com/justwatch/facebook-marketing-api-golang-sdk/marketing/v20"
)

func main(){
	fbService, _ := v20.New(l, accessToken, appSecret)
	
	// [Code snippets from other example below go here]
}

Create a campaign

c := v20.Campaign{
	// Populate struct values
}
id, _ := fbService.Campaigns.Create(ctx, c)

Upload an external asset to Facebook

accountID := "[account id]"
imagePath := "[path to image]"
imageName := "[image name]"

file, _ := os.Open(imagePath)
im, _ := fbService.Images.Upload(context.Background(), accountID,imageName, file)

// You now can access the ID of the uploaded image via im.ID
fmt.Println("Uploaded image has id: ", im.ID)
accountID := "[account id]"
videoPath := "[path to video]"
videoName := "[video name]"

file, _ := os.Open(videoPath)
vid, _ := fbService.Videos.Upload(context.Background(), accountID, videoName, file)

// You now can access the ID of the uploaded video via vid.ID
fmt.Println("Uploaded video has id: ", vid.ID)

Read campaigns from an account

id := "[account_id]"

campaigns, _ := p.fbService.Campaigns.List(id).Do(ctx)

Get reporting data for an account at adset level

// put the columns you need for the report
columns := []string {}

//account id you want the report from
id := "[account_id]"


// Create new report
report := fbService.Insights.NewReport(id)

// Configure report
report.Level("adset").
	DailyTimeIncrement(true). // get day by day reporting
		Fields(columns...). // the fields you want your report to have
			DatePreset("lifetime") // the time period for the report

// pass a channel which gets populated with results
ch := make(chan v20.Insight)
nRecords,_ := report.GenerateReport(ctx,ch)

//range over the channel to get Insight objects
for insight := range ch {
    fmt.Println("New report result: ", insight)
}

FAQs

Package last updated on 11 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc