fbvideo

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

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

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

README

go-fbvideo

A small lib to help me upload video to a facebook resource (user, page, group, event)

Example:
package main

import (
	"fmt"
	"log"

	"github.com/canhlinh/go-fbvideo"
)

func main() {
	// You have to export your acess token to FB_ACCESS_TOKEN variable
	// run command: export FB_ACCESS_TOKEN="Your access token"
	accessToken := fbvideo.GetAccessToken()
	me, err := fbvideo.GetMe(accessToken)
	if err != nil {
		panic(err)
	}
	meID := me["id"].(string)

	uploadSession := fbvideo.NewUploadSession("../testdata/SampleVideo_720x480_10mb.mp4", meID, accessToken)

	// Uploads the video to your wall, only you can see it
	option := fbvideo.Option{Privacy: &fbvideo.Privacy{Value: fbvideo.PrivacySelf}}
	videoID, err := uploadSession.Upload(option)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("video_id %s", videoID)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAccessToken

func GetAccessToken() string

func StringFromBody

func StringFromBody(body io.Reader) string

Types

type ChunkInfo

type ChunkInfo struct {
	Path        string
	Body        io.Reader
	ContentType string
}

type ChunkOffset

type ChunkOffset struct {
	StartOffset string `json:"start_offset"`
	EndOffset   string `json:"end_offset"`
}

type Error

type Error struct {
	Struct struct {
		Message      string `json:"message"`
		Type         string `json:"type"`
		Code         int    `json:"190"`
		ErrorSubCode int    `json:"463"`
		FBTraceID    string `json:"fbtrace_id"`
	} `json:"error"`
}

func NewErrorFromBody

func NewErrorFromBody(body io.ReadCloser) *Error

type LongLivedToken

type LongLivedToken struct {
	AccessToken string `json:"access_token"`
	ExpiresIn   int64  `json:"expires_in"`
}

func NewLongLivedTokenFromBody

func NewLongLivedTokenFromBody(body io.ReadCloser) *LongLivedToken

type LongLivedTokenGenerater

type LongLivedTokenGenerater struct {
	ClientID     string
	ClientSecret string
	RedirectURL  string
	// contains filtered or unexported fields
}

func NewLongLivedTokenGenerater

func NewLongLivedTokenGenerater(clientID, clientSecret, redirectURL string) *LongLivedTokenGenerater

func (*LongLivedTokenGenerater) GenerateLongLivedToken

func (g *LongLivedTokenGenerater) GenerateLongLivedToken(shortToken string) (string, error)

GenerateLongLivedToken generate a long-lived token from the short token.

func (*LongLivedTokenGenerater) RefreshLongLivedToken

func (g *LongLivedTokenGenerater) RefreshLongLivedToken(longLivedToken string) (string, error)

RefreshLongLivedToken get a new long-lived token from an old long-lived token.

type Map

type Map map[string]interface{}

func GetMe

func GetMe(accessToken string) (Map, error)

func GetResourceInfo

func GetResourceInfo(resourseID string, accessToken string) (Map, error)

type Option

type Option struct {
	Privacy *Privacy
}

type Privacy

type Privacy struct {
	Value PrivacyValue `json:"value"`
	Allow string       `json:"allow"`
	Deny  string       `json:"deny"`
}

func (*Privacy) JSON

func (p *Privacy) JSON() string

type PrivacyValue

type PrivacyValue string

PrivacyValue Determines the privacy settings of the video. If not supplied, this defaults to the privacy level granted to the app in the Login Dialog. This field cannot be used to set a more open privacy setting than the one granted.

const (
	PrivacyEveryOne         PrivacyValue = "EVERYONE"
	PrivacyAllFriends       PrivacyValue = "ALL_FRIENDS"
	PrivacyFriendsOfFriends PrivacyValue = "FRIENDS_OF_FRIENDS"
	PrivacyCustom           PrivacyValue = "CUSTOM"
	PrivacySelf             PrivacyValue = "SELF"
)

type Result

type Result struct {
	Success bool `json:"success"`
}

type SessionInfo

type SessionInfo struct {
	*ChunkOffset
	UploadSessionID string `json:"upload_session_id"`
	VideoID         string `json:"video_id"`
}

type UploadSession

type UploadSession struct {
	// ID of a fb resource, possible value are user, page, event, group.
	ID string

	// AccessToken the token has permission to upload video to the fb resource.
	AccessToken string

	// Endpoint url to upload video
	Endpoint  string
	Transport http.RoundTripper

	// FilePath location of the file in disk
	FilePath string
	// contains filtered or unexported fields
}

UploadSession facebook upload session struct

func NewUploadSession

func NewUploadSession(filePath string, fbResourceID string, accessToken string) *UploadSession

NewUploadSession create a new fb upload session.

func (*UploadSession) Upload

func (uploadSession *UploadSession) Upload(option Option) (string, error)

Upload upload the file to fb server

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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