instagram

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

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

Go to latest
Published: Sep 22, 2024 License: MIT Imports: 10 Imported by: 0

README

goth-instagram

This package implements the Instagram Graph API for Goth OAuth library.

Installation

go get github.com/chenmingbiao/goth-instagram

Usage

To use this provider with Goth, you need to set it up with your Instagram application credentials. Here's an example of how to configure and use the Instagram provider:

package main

import (
    "fmt"
    "net/http"
    "os"
	
    "github.com/markbates/goth"
    "github.com/markbates/goth/gothic"
    "github.com/chenmingbiao/goth-instagram"
)

func main() {
    goth.UseProviders(
        instagram.New(os.Getenv("INSTAGRAM_CLIENT_ID"), os.Getenv("INSTAGRAM_CLIENT_SECRET"), "http://localhost:3000/auth/instagram/callback"),
    )
    http.HandleFunc("/auth/instagram", func(w http.ResponseWriter, r *http.Request) {
        gothic.BeginAuthHandler(w, r)
    })
    http.HandleFunc("/auth/instagram/callback", func(w http.ResponseWriter, r *http.Request) {
        user, err := gothic.CompleteUserAuth(w, r)
        if err != nil {
            http.Error(w, err.Error(), http.StatusInternalServerError)
            return
        }
        fmt.Fprintf(w, "%+v", user)
    })
    http.ListenAndServe(":3000", nil)
}

Make sure to set the INSTAGRAM_CLIENT_ID and INSTAGRAM_CLIENT_SECRET environment variables with your Instagram application credentials.

Configuration

The provider is initialized with New() and takes three arguments:

  • clientKey: Your Instagram application's App ID
  • secret: Your Instagram application's App Secret
  • callbackURL: The URL to redirect to after authentication You can also pass additional scopes as variadic arguments to New(). If no scopes are provided, it defaults to user_profile.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

type Provider struct {
	ClientKey   string
	Secret      string
	CallbackURL string
	// contains filtered or unexported fields
}

Provider is the implementation of `goth.Provider` for accessing Instagram.

func New

func New(clientKey, secret, callbackURL string, scopes ...string) *Provider

New creates a new Instagram provider, and sets up important connection details.

func (*Provider) BeginAuth

func (p *Provider) BeginAuth(state string) (goth.Session, error)

BeginAuth asks Instagram for an authentication end-point.

func (*Provider) Client

func (p *Provider) Client() *http.Client

func (*Provider) Debug

func (p *Provider) Debug(debug bool)

Debug is a no-op for the instagram package.

func (*Provider) FetchUser

func (p *Provider) FetchUser(session goth.Session) (goth.User, error)

FetchUser will go to Instagram and access basic information about the user.

func (*Provider) Name

func (p *Provider) Name() string

Name is the name used to retrieve this provider later.

func (*Provider) RefreshToken

func (p *Provider) RefreshToken(_ string) (*oauth2.Token, error)

func (*Provider) RefreshTokenAvailable

func (p *Provider) RefreshTokenAvailable() bool

func (*Provider) SetName

func (p *Provider) SetName(name string)

SetName is to update the name of the provider (needed in case of multiple providers of the same type)

func (*Provider) UnmarshalSession

func (p *Provider) UnmarshalSession(data string) (goth.Session, error)

UnmarshalSession will unmarshal a JSON string into a session.

type Session

type Session struct {
	AuthURL      string
	AccessToken  string
	RefreshToken string
	ExpiresAt    time.Time
}

Session stores data during the auth process with Instagram.

func (*Session) Authorize

func (s *Session) Authorize(provider goth.Provider, params goth.Params) (string, error)

Authorize the session with Instagram and return the access token to be stored for future use.

func (Session) GetAuthURL

func (s Session) GetAuthURL() (string, error)

GetAuthURL will return the URL set by calling the `BeginAuth` function on the Instagram provider.

func (Session) Marshal

func (s Session) Marshal() string

Marshal the session into a string

func (*Session) String

func (s *Session) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳