fb

package module
v0.0.0-...-a35bd36 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 4, 2018 License: GPL-3.0 Imports: 13 Imported by: 0

README

go-graph-fb Build Status

This is a Go library (package fb) that makes using the Facebook Graph API easy.

Get It
go get github.com/dchenk/go-graph-fb
Documentation

Check out the GoDoc: godoc.org/github.com/dchenk/go-graph-fb

Documentation

Overview

Package fb provides helpers for using the Facebook Graph API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppsecretProof

func AppsecretProof(userAccessToken, appSecret string) (string, error)

AppsecretProof generates an app secret proof for an app. The userAccessToken must belong to an admin of the app. Info: https://developers.facebook.com/docs/graph-api/securing-requests/#appsecret_proof

func CreateSystemTokenReq

func CreateSystemTokenReq(userToken, systemUserID, appSecretProof, appID string, scope []string) *http.Request

CreateSystemTokenReq sets up an http.Request for getting a system user token. Info: https://developers.facebook.com/docs/marketing-api/businessmanager/systemuser/#systemusertoken

func DebugTokenReq

func DebugTokenReq(accessToken, tokenToDebug string) *http.Request

DebugTokenReq sets up an http.Request for debugging a token.

func ExtendedUserAccessTokenReq

func ExtendedUserAccessTokenReq(userToken, appID, appSecret string) *http.Request

func FormLeadDataReq

func FormLeadDataReq(pageAccessToken, leadID string) *http.Request

func FormLeadsReq

func FormLeadsReq(pageAccessToken, formID string) *http.Request

Fields queried: created_time,id,form_id,field_data

func InstallSystemUserAppReq

func InstallSystemUserAppReq(adminAccessToken, appID, appUserID string) *http.Request

InstallSystemUserAppReq installs an app for a system user. The appUserID must be an app-scoped system user iD, which you can get with ListSystemUsersReq (adminToken must belong to an admin of the business or to an admin system user).

func IsErrResponse

func IsErrResponse(err error) bool

IsErrResponse says if the error is of type *ErrResponse, which Facebook can send as part of a response payload.

func ListAppSubscriptionsReq

func ListAppSubscriptionsReq(appAccessToken, appID string) *http.Request

func ListPageSubscribedAppsReq

func ListPageSubscribedAppsReq(pageAccessToken, pageID string) *http.Request

ListPageSubscribedAppsReq returns a request to query the Facebook apps that are subscribed to a page's events.

func ListSystemUsersReq

func ListSystemUsersReq(adminToken, businessID string, fields []string) *http.Request

ListSystemUsersReq lists the system users and admin system users for the business (adminToken must belong to an admin of the business or to an admin system user). The ID of each user returned is an app-scoped user ID. Use the SystemUserList type for responses. The fields parameter specifies which fields to show for the users; the default fields (if given nil) are given in the SystemUserList struct.

func ListUserPagesFieldsReq

func ListUserPagesFieldsReq(accessToken string, fields []string) *http.Request

ListUserPagesFieldsReq lists the pages belonging to a user using a user access token with the specified fields.

func ListUserPagesReq

func ListUserPagesReq(accessToken string) *http.Request

ListUserPagesReq lists the pages belonging to a user using a user access token with the fields: id,name,access_token,category,perms,picture{url}

func NextPage

func NextPage(nextURL string, client *http.Client) (*http.Response, error)

NextPage makes a request to nextURL using the given client. If Client is nil, then http.DefaultClient is used.

func PageLeadgenSetupReq

func PageLeadgenSetupReq(pageAccessToken, pageID string) *http.Request

PageLeadgenSetupReq returns a request to query the basic settings concerning a page's leadgen setup. Fields retrieved: id,name,leadgen_has_crm_integration,leadgen_forms{id,name,status}

func ReadResponse

func ReadResponse(res *http.Response, v interface{}) error

ReadResponse simply reads the response and decodes it into v, which should be a non-nil pointer to a variable that can take an error response (in the Facebook Graph way) or the actual response expected. This function closes the http.Response body upon returning.

func Req

func Req(method, nodeEdge string, accessToken string, fields []string, params ...Param) *http.Request

Req sets up a request to the Facebook API but does not run it. The method should one of GET, POST, or DELETE. The nodeEdge parameter should not have a leading slash or the Graph API version (currently set to 2.12). Leave the fields slice empty or nil to not specify a fields parameter.

func ReqDo

func ReqDo(method, nodeEdge string, accessToken string, fields []string, params ...Param) (*http.Response, error)

ReqDo uses Req to set up the request and then runs Do on it. The client request timeout is set to 12 seconds.

func SubscribeAppToPageReq

func SubscribeAppToPageReq(pageAccessToken, pageID string) *http.Request

SubscribeAppToPageReq returns a request that can be used to subscribe an app to a page. A page access token belonging to the page must be used for this.

func UnsubscribeFromPageReq

func UnsubscribeFromPageReq(appAccessToken, pageID string) *http.Request

UnsubscribeFromPageReq unsubscribes the app from notifications for the page.

Types

type AppSubscriptionsList

type AppSubscriptionsList struct {
	Data []struct {
		Object      string `json:"object"`
		CallbackURL string `json:"callback_url"`
		Active      bool   `json:"active"`
		Fields      []struct {
			Name    string `json:"name"`
			Version string `json:"version"`
		} `json:"fields"`
	} `json:"data"`
	Error *ErrResponse `json:"error"`
}

type AssignedAdAccountsList

type AssignedAdAccountsList struct {
	Data []struct {
		AccountID string `json:"account_id"`
		Name      string `json:"name"`
		Role      string `json:"role"`
	} `json:"data"`
	Paging CursorPaging `json:"paging"`
	Error  *ErrResponse `json:"error"` // useful only when requesting list alone
}

type AssignedPagesList

type AssignedPagesList struct {
	Data []struct {
		ID      string `json:"id"`
		Name    string `json:"name"`
		Role    string `json:"role"`
		Picture struct {
			Data struct {
				URL string `json:"url"`
			} `json:"data"`
		} `json:"picture"`
	} `json:"data"`
	Paging CursorPaging `json:"paging"`
	Error  *ErrResponse `json:"error"` // useful only when requesting list alone
}

type CursorPaging

type CursorPaging struct {
	Cursors struct {
		Before string `json:"before"`
		After  string `json:"after"`
	} `json:"cursors"`
	Previous string `json:"previous"`
	Next     string `json:"next"`
	Limit    string `json:"limit"`
}

type ErrResponse

type ErrResponse struct {
	Message          string `json:"message"`
	Type             string `json:"type"`
	Code             int64  `json:"code"`
	ErrorSubcode     int64  `json:"error_subcode"`
	ErrorUserTitle   string `json:"error_user_title"`
	ErrorUserMessage string `json:"error_user_message"`
	FbTraceID        string `json:"fbtrace_id"`
}

func (*ErrResponse) Error

func (er *ErrResponse) Error() string

Error gives the main details of the error code and message.

func (*ErrResponse) UserErrMessage

func (er *ErrResponse) UserErrMessage() string

UserErrMessage summarizes the error in a way that can be displayed to users.

type FormLead

type FormLead struct {
	CreatedTime string `json:"created_time"`
	ID          string `json:"id"`
	FieldData   []struct {
		Name   string   `json:"name"`
		Values []string `json:"values"`
	} `json:"field_data"`
	Error *ErrResponse `json:"error"`
}

func (*FormLead) MarshalJSON

func (fl *FormLead) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler for the FormLead type. This function always returns a nil error.

type FormLeadsList

type FormLeadsList struct {
	Data   []FormLead   `json:"data"`
	Paging CursorPaging `json:"paging"`
	Error  *ErrResponse `json:"error"`
}

The FormLeadsList type represents a bulk read response of leads collected for a form.

type GraphResponseMe

type GraphResponseMe struct {
	ID    string       `json:"id"`
	Name  string       `json:"name"`
	Email string       `json:"email"`
	Error *ErrResponse `json:"error"`
}

type GraphResponsePage

type GraphResponsePage struct {
	Data struct {
		ID      string `json:"id"` // numeric string
		Name    string `json:"name"`
		Article string `json:"article"`
		Type    string `json:"type"`
	} `json:"data"`
	Paging CursorPaging `json:"paging"`
	Error  *ErrResponse `json:"error"`
}

type LeadGenEntry

type LeadGenEntry struct {
	AdID        string `json:"ad_id"`
	FormID      string `json:"form_id"`
	LeadgenID   string `json:"leadgen_id"`
	PageID      string `json:"page_id"`
	AdgroupID   string `json:"adgroup_id"`
	CreatedTime int64  `json:"created_time"`
}

A LeadGenEntry is a Page webhook notification value for the field "leadgen".

func (*LeadGenEntry) MarshalJSON

func (le *LeadGenEntry) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler for the LeadGenEntry type. This function always returns a nil error.

type OffsetPaging

type OffsetPaging struct {
	Offset   int64  `json:"offset"`
	Limit    int64  `json:"limit"`
	Previous string `json:"previous"`
	Next     string `json:"next"`
}

type PageLeadgenForm

type PageLeadgenForm struct {
	ID     string `json:"id"`
	Name   string `json:"name"`
	Status string `json:"status"`
}

type PageLeadgenFormList

type PageLeadgenFormList struct {
	Data   []PageLeadgenForm `json:"data"`
	Paging CursorPaging      `json:"paging"`
	Error  *ErrResponse      `json:"error"`
}

A PageLeadgenFormList is used to read the response from a "next" page URL given to page through the list of lead ads forms belonging to a page.

type PageLeadgenSetup

type PageLeadgenSetup struct {
	ID                       string `json:"id"` // The page ID
	Name                     string `json:"name"`
	LeadgenHasCrmIntegration bool   `json:"leadgen_has_crm_integration"`
	LeadgenForms             struct {
		Data   []PageLeadgenForm `json:"data"`
		Paging CursorPaging      `json:"paging"`
	} `json:"leadgen_forms"`
	Error *ErrResponse `json:"error"` // nil if no error is given
}

type Param

type Param interface {
	Key() string
	Val() string
}

A Param is a key => value pair to be sent in the request.

type ParamStrInt

type ParamStrInt struct {
	K string
	V int64
}

A ParamStrInt contains key-value pair where the key is a string and the value an int64.

func (*ParamStrInt) Key

func (psi *ParamStrInt) Key() string

func (*ParamStrInt) Val

func (psi *ParamStrInt) Val() string

type ParamStrStr

type ParamStrStr struct {
	K, V string
}

A ParamStrStr contains key-value pair where both elements are strings.

func (*ParamStrStr) Key

func (pss *ParamStrStr) Key() string

func (*ParamStrStr) Val

func (pss *ParamStrStr) Val() string

type SubscribeAppResponse

type SubscribeAppResponse struct {
	Success bool         `json:"success"`
	Error   *ErrResponse `json:"error"` // nil if no error is given
}

A SubscribeAppResponse represents the format in which a response indicates if an app successfully subscribed to a page.

type SubscribedAppsList

type SubscribedAppsList struct {
	Data []struct {
		Category string `json:"category"`
		Link     string `json:"link"`
		Name     string `json:"name"`
		ID       string `json:"id"`
	} `json:"data"`
	Paging CursorPaging `json:"paging"`
	Error  *ErrResponse `json:"error"` // nil if no error is given
}

A SubscribedAppsList response represents the list of apps subscribed to a page.

type SystemUserList

type SystemUserList struct {
	Data []struct {
		ID                 string                 `json:"id"`
		Name               string                 `json:"name"`
		AssignedAdAccounts AssignedAdAccountsList `json:"assigned_ad_accounts"`
		AssignedPages      AssignedPagesList      `json:"assigned_pages"`
	} `json:"data"`
	Paging CursorPaging `json:"paging"`
	Error  *ErrResponse `json:"error"` // nil if no error is given by FB
}

SystemUserList sample payload:

{
	"data":[
		{
			"id":"1000081799813",
			"name":"Reporting server",
			"assigned_ad_accounts": {
				"data": [
					{
						"id":"act_XXXXX",
						"account_id":"XXXXXXXXX",
						"role":"ADMIN"
					}
				]
			},
			"assigned_pages": {
				"data": [
					{
						"id":"1750248626186",
						"role":"INSIGHTS_ANALYST"
					}
				]
			}
		}
	]
}

type TimePaging

type TimePaging struct {
	Until    int64  `json:"until"`
	Since    int64  `json:"since"`
	Limit    int64  `json:"limit"`
	Previous string `json:"previous"`
	Next     string `json:"next"`
}

type TokenDebug

type TokenDebug struct {
	Data struct {
		IsValid     bool     `json:"is_valid"`
		AppID       string   `json:"app_id"`
		Application string   `json:"application"`
		Type        string   `json:"type"`
		IssuedAt    int64    `json:"issued_at"`
		ExpiresAt   int64    `json:"expires_at"`
		Scopes      []string `json:"scopes"`
		UserID      string   `json:"user_id"`
		Error       struct {
			Code    int64  `json:"code"`
			Message string `json:"message"`
		} `json:"error"`
	}
	Error *ErrResponse `json:"error"` // nil if no error is given by FB; if nil, no Data will be sent
}

A TokenDebug represents a Facebook response for the token debugging API. Info: https://developers.facebook.com/docs/graph-api/reference/v2.12/debug_token

func DebugToken

func DebugToken(accessToken, tokenToDebug string, client *http.Client) (*TokenDebug, error)

DebugToken sends a token debug request to Facebook and reads the response. If the client given is nil, then http.DefaultClient is used.

type TokenResponse

type TokenResponse struct {
	AccessToken string       `json:"access_token"`
	TokenType   string       `json:"token_type"`
	ExpiresIn   int          `json:"expires_in"`
	Error       *ErrResponse `json:"error"` // nil if no error is given
}

A TokenResponse represents a response from Facebook containing a token.

type UserPage

type UserPage struct {
	ID           string `json:"id"`
	Name         string `json:"name"`
	AccessToken  string `json:"access_token"`
	Category     string `json:"category"`
	CategoryList []struct {
		ID   string `json:"id"`
		Name string `json:"name"`
	} `json:"category_list"`
	Picture struct {
		Data struct {
			URL string `json:"url"`
		} `json:"data"`
	} `json:"picture"`
	Perms []string `json:"perms"`
}

type UserPagesList

type UserPagesList struct {
	Data   []UserPage   `json:"data"`
	Paging CursorPaging `json:"paging"`
	Error  *ErrResponse `json:"error"` // nil if no error is given
}

A UserPagesList response lists the pages belonging to a user.

type WebhookNotif

type WebhookNotif struct {
	Object string `json:"object"` // enum{user, page, permissions, payments}
	Entry  []struct {
		ID            string   `json:"id"`
		ChangedFields []string `json:"changed_fields"` // Fields include, e.g., for Page "leadgen", "location", "messages", etc.
		Changes       []struct {
			Field string          `json:"field"`
			Value json.RawMessage `json:"value"` // Not set for some endpoints.
		} `json:"changes"`
		Time int `json:"time"` // A Unix timestamp.
	} `json:"entry"`
}

A WebhookNotif represents any webhook notification payload. Info https://developers.facebook.com/docs/graph-api/webhooks

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL