$ go get github.com/wuriyanto48/go-social
OAuth2 using Facebook login
-
Getting Authorization Code First
https://www.facebook.com/dialog/oauth?client_id={your_client_id}&redirect_uri=http://localhost:8080/callback&response_type=code
-
Place the Authorization Code to the second parameter of
GetAccessToken(ctx, "authorization_code")
function
package main
import (
"context"
"fmt"
"github.com/wuriyanto48/go-social"
"github.com/wuriyanto48/go-social/pkg/facebook"
)
func main() {
f, err := social.New(social.Facebook, "client_id", "client_secret", "", "http://localhost:8080/callback", "", 0)
if err != nil {
fmt.Println(err)
}
// using context for cancellation
ctx := context.Background()
err = f.GetAccessToken(ctx, "authorization_code")
if err != nil {
fmt.Println(err)
}
result, err := f.GetUser(ctx)
if err != nil {
fmt.Println(err)
}
user, _ := result.(*facebook.User)
fmt.Println(user.Picture)
}
- Add Twitter implementation