facebook

package module
v0.0.0-...-3ac162f Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2016 License: MIT Imports: 8 Imported by: 0

README

go-facebook

A basic Facebook SDK for Go.

travis-ci status for jimmysawczuk/go-facebook GoDoc Go Report Card

Installation

Install this package by typing go get github.com/jimmysawczuk/go-facebook in your terminal. You can then use it in your import statement like so:

import (
	"github.com/jimmysawczuk/go-facebook"
)

Example

package main

import (
    "github.com/jimmysawczuk/go-facebook"
    "github.com/jimmysawczuk/go-facebook/types"
    "fmt"
)

func main() {
    fb := facebook.New("<app id>", "<secret>")
    fb.SetAccessToken("<token>")

    user, err := fb.GetUser("me")
    fmt.Println(user, err)

    resp := types.Page{}
    err = fb.Get("/starbucks", nil).Exec(&resp)
    fmt.Println(resp, err)
}

Documentation

You can find the latest godoc output for this repository at GoDoc.org.

License

go-facebook is released under the MIT license.

Documentation

Overview

Package facebook implements a few functions that basically wrap Go's REST client to work with the Facebook Graph API.

Index

Constants

View Source
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

View Source
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

func New(appID string, secret string) (f *Client)

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

func (f *Client) GetAppAccessToken() (string, error)

GetAppAccessToken builds an app access token for the client ID/secret of the client.

func (*Client) GetPage

func (c *Client) GetPage(pageIdentifier string) (page types.Page, err error)

GetPage builds and executes a GraphRequest for /{page_identifier}, tries to marshal the response into a types.Page.

func (*Client) GetUser

func (c *Client) GetUser(userIdentifier string) (user types.User, err error)

GetUser builds and executes a GraphRequest for /{page_identifier}, tries to marshal the response into a types.User.

func (*Client) LintAccessToken

func (f *Client) LintAccessToken() (err error)

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

func (f *Client) SetAccessToken(at string)

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

type GraphQueryString url.Values

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

type HTTPClient interface {
	Do(*http.Request) (*http.Response, error)
}

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)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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