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

github.com/deiwin/facebook

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/deiwin/facebook

  • v0.0.0-20150906205251-e3366e61ab85
  • Source
  • Go
  • Socket score

Version published
Created
Source

Facebook API wrapper in Go

GoDoc

This is a work in progress. It is currently used by deiwin/luncher-api and only implements the functionality needed by that project.

Tutorial

Configuration

Using $FACEBOOK_APP_SECRET and $FACEBOOK_APP_ID environment variables:

redirectURL := "http://your.domain.com/login/facebook/redirected"
scopes := []string{"manage_pages", "publish_actions", "whatever"}
facebookConfig := facebook.NewConfig(redirectURL, scopes)

However, if you wish, you can also manage your app secret and id differently:

facebookConfig := facebook.Config{
  AppID:       "your_app_id",
  AppSecret:   "your_app_secret",
  RedirectURL: "http://your.domain.com/login/facebook/redirected",
  Scopes:      []string{"manage_pages", "publish_actions", "whatever"},
}

Authentication

Redirecting users to Facebook for login
facebookAuthenticator := facebook.NewAuthenticator(facebookConfig)

// In an handler for the login request
session := "your_identifier_for_the_current_user_session"
redirectURL := facebookAuthenticator.AuthURL(session)
http.Redirect(w, r, redirectURL, http.StatusSeeOther)
Handling users redirected back from Facebook
// In an handler for the RedirectURL in the configuration.
// E.g "http://your.domain.com/login/facebook/redirected"
session := "your_identifier_for_the_current_user_session"
tok, err := facebookAuthenticator.Token(session, r)
if err != nil {
  if err == facebook.ErrMissingState {
    http.Error(w, "Expecting a 'state' value", http.StatusBadRequest)
  } else if err == facebook.ErrInvalidState {
    http.Error(w, "Invalid 'state' value", http.StatusForbidden)
  } else if err == facebook.ErrMissingCode {
    http.Error(w, "Expecting a 'code' value", http.StatusBadRequest)
  }
  http.Error(w, "", http.StatusInternalServerError)
}

Using the API

Receiving information about the current user
api := fb.auth.APIConnection(tok)
user, err := api.Me()
if err != nil {
  ...
}
return user.ID

See the GoDoc for the API for more options.

FAQs

Package last updated on 06 Sep 2015

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