Documentation ¶
Overview ¶
Package facebook implements a few functions that basically wrap Go's REST client to work with the Facebook Graph API.
Index ¶
- Constants
- Variables
- type AccessToken
- type Client
- func (f *Client) AccessToken() AccessToken
- func (f *Client) Get(path string, params GraphQueryString) *GraphRequest
- func (f *Client) GetAppAccessToken() (string, error)
- func (c *Client) GetPage(pageIdentifier string) (page types.Page, err error)
- func (c *Client) GetUser(userIdentifier string) (user types.User, err error)
- func (f *Client) LintAccessToken() (err error)
- func (f *Client) NewGraphRequest(method HTTPMethod, path string, params GraphQueryString) *GraphRequest
- func (f *Client) Post(path string, params GraphQueryString) *GraphRequest
- func (f *Client) Put(path string, params GraphQueryString) *GraphRequest
- func (f *Client) SetAccessToken(at string)
- type GraphAPIVersion
- type GraphError
- type GraphQueryString
- type GraphRequest
- type HTTPClient
- type HTTPMethod
Constants ¶
const ( Get HTTPMethod = "GET" Post = "POST" Put = "PUT" Unversioned GraphAPIVersion = "" Version10 = "v1.0" Version20 = "v2.0" Version21 = "v2.1" Version22 = "v2.2" Version23 = "v2.3" Version24 = "v2.4" Version25 = "v2.5" Version26 = "v2.6" Latest = "v2.6" )
Some useful constants for building requests
Variables ¶
var BlankClient = New("", "")
An empty Facebook API client with which you can make public requests or set an arbitrary access token.
Functions ¶
This section is empty.
Types ¶
type AccessToken ¶
type AccessToken struct {
// contains filtered or unexported fields
}
AccessToken represents an Graph API access token
func (AccessToken) Empty ¶
func (at AccessToken) Empty() bool
Empty returns true if the access token is equal to the empty string.
func (AccessToken) Info ¶
func (at AccessToken) Info() string
Info returns a formatted description of the access token, including the token itself, the permissions, the expiry and the validity.
func (*AccessToken) Lint ¶
func (at *AccessToken) Lint(f *Client) error
Lint figures out what permissions are attached to the current access token.
func (AccessToken) String ¶
func (at AccessToken) String() string
String returns the access token as a string
func (AccessToken) Valid ¶
func (at AccessToken) Valid() bool
Valid returns the validity status for the token (but doesn't attempt to determine it if not present)
type Client ¶
type Client struct { // The default Graph API version to use DefaultVersion GraphAPIVersion // The HTTP client to use when making API requests HTTPClient HTTPClient // contains filtered or unexported fields }
Client is an object which represents a pathway to the Facebook Graph API.
func New ¶
New returns a new *Client. Pass empty strings here if you don't need the object to have your App ID or Secret.
func (*Client) AccessToken ¶
func (f *Client) AccessToken() AccessToken
AccessToken returns the working access token.
func (*Client) Get ¶
func (f *Client) Get(path string, params GraphQueryString) *GraphRequest
Get is a wrapper for client.NewGraphRequest(Get, path, params)
func (*Client) GetAppAccessToken ¶
GetAppAccessToken builds an app access token for the client ID/secret of the client.
func (*Client) GetPage ¶
GetPage builds and executes a GraphRequest for /{page_identifier}, tries to marshal the response into a types.Page.
func (*Client) GetUser ¶
GetUser builds and executes a GraphRequest for /{page_identifier}, tries to marshal the response into a types.User.
func (*Client) LintAccessToken ¶
LintAccessToken is an alias for client.AccessToken().Lint().
func (*Client) NewGraphRequest ¶
func (f *Client) NewGraphRequest(method HTTPMethod, path string, params GraphQueryString) *GraphRequest
NewGraphRequest builds a new GraphRequest with the passed method, path and query string parameters. If no access token is passed, but one is set in the client, it will be appended automatically. Assumes the response will be application/json.
func (*Client) Post ¶
func (f *Client) Post(path string, params GraphQueryString) *GraphRequest
Post is a wrapper for client.NewGraphRequest(Post, path, params)
func (*Client) Put ¶
func (f *Client) Put(path string, params GraphQueryString) *GraphRequest
Put is a wrapper for client.NewGraphRequest(Put, path, params)
func (*Client) SetAccessToken ¶
SetAccessToken sets the working access token.
type GraphAPIVersion ¶
type GraphAPIVersion string
GraphAPIVersion is a string which represents the Graph API version to use (e.g. v2.4)
type GraphError ¶
type GraphError struct { Code int `json:"code"` Subcode int `json:"error_subcode"` Message string `json:"message"` Type string `json:"type"` HTTPStatus int `json:"http"` }
GraphError is a specific error that's returned from Facebook if there's an error with a request to the Graph API.
func (GraphError) Error ¶
func (e GraphError) Error() string
func (GraphError) String ¶
func (e GraphError) String() string
String returns a string representation of the error in the format: Error <code>: <message>.
func (*GraphError) UnmarshalJSON ¶
func (e *GraphError) UnmarshalJSON(in []byte) (err error)
UnmarshalJSON implements the json.Unmarshaler interface.
type GraphQueryString ¶
GraphQueryString is a query string for a GraphRequest
type GraphRequest ¶
type GraphRequest struct { // The HTTP method used Method HTTPMethod // Defaults to the client's DefaultVersion. Version GraphAPIVersion // e.g. /me or /starbucks Path string // A url.Values representation of desired query string parameters, e.g. width=50&height=50 Query GraphQueryString // True if the expected content-type of the return is application/json. If this is true, Exec() will try // to marshal the response as JSON into the target object. Otherwise, it will just set the target object // as a []byte. IsJSON bool // contains filtered or unexported fields }
GraphRequest is an HTTP request to the Graph API
func (*GraphRequest) Exec ¶
func (r *GraphRequest) Exec(target interface{}) error
Exec executes the given request. Returns a GraphError if the response from Facebook is an error, or just a normal error if something goes wrong before that or during unmarshaling.
func (*GraphRequest) SetVersion ¶
func (r *GraphRequest) SetVersion(v GraphAPIVersion) *GraphRequest
SetVersion sets the Graph API version on the request.
type HTTPClient ¶
HTTPClient is the interface which is used to communicate with Facebook. It defaults to http.DefaultClient, but is implemented this way to allow for middleware functionality later on.
type HTTPMethod ¶
type HTTPMethod string
HTTPMethod is a string which represents an HTTP method (e.g. GET, POST or PUT)