gostagram

package module
v0.0.0-...-11ba34f Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2017 License: MIT Imports: 12 Imported by: 0

README

Gostagram

Unofficial and easy to use instagram client for go.

gostagram documentation Release license


Quick Start.

Create Instagram Client

Go to instagram developer website and create a developer account, then register a new instagram client.

Implement Oauth2 Protocol

Get the access token, implementing oauth2 authorization protocol. I do recommmend oauth2 for this job. Here you can find an oauth2 example.

Download and Installation

go get github.com/ljesparis/gostagram

Usage

Basic example, using an client to consume an instagram endpoint.

package main

import (
    "fmt"
    "github.com/ljesparis/gostagram"
)

func main() {
    client := gostagram.NewClient("access_token")
    user, err := client.GetCurrentUser()
    
    if err != nil {
        fmt.Println(err)
    } else {
        fmt.Println(user.Id)
        fmt.Println(user.Username)
        fmt.Println(user.FullName)
    }
}

If you want to enable instagram signed requests mode you have to tell gostagram client, that you want to sig a request.

package main

import (
    "fmt"
    "github.com/ljesparis/gostagram"
)

func main() {
    client := gostagram.NewClient("access_token")
    client.SetSignedRequest(true)
    client.SetClientSecret("client secret")
    
    
    tags, err := client.SearchTags("golang")
    
    if err != nil {
        fmt.Println(err)
    } else {
        for _, tag := range tags {
          fmt.Println("Tag name: ", tag.Name)
        }
    }
}

Tests.

Before executing gostagram tests, please get access token, client secret and complete every empty variable in all test file, why? well, that way you could test every method with your own parameters, otherwise multiples errors will be thrown.

Note: test every method one by one, use the makefile to optimize that process.

Support us.

Contribute.

Please use Github issue tracker for everything.

  • Report issues.
  • Improve/Fix documentation.
  • Suggest new features or enhancements.

License.

gostagram license MIT

Documentation

Overview

gostagram is an unofficial go client for the instagram api.

note: there's two way to get the access token, using oauth2 golang library or using curl (both ways need a local server to get the token).

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// errors that should be throw
	// if you want to post a comment
	// incorrectly.
	CommentsUrlExceed           = errors.New("Comment cannot contain more than 1 URL.")
	CommentsHashtagExceed       = errors.New("Comment cannot contain more than 4 hashtags.")
	CommentsMaxLengthExceed     = errors.New("Comment cannot exceed 300 characters.")
	CommentsCapitalLettersError = errors.New("Comment cannot consist of all capital letters")
	MissingCommentError         = errors.New("Comment cannot be empty.")
)
View Source
var (
	ClientSecretNotSetError     = errors.New("Client secret not set for signed request.")
	WrongInstagramEndpointError = errors.New("Wrong instagram endpoint.")
)
View Source
var (
	SubscriptionError = errors.New("Subscriptions not yet supported.")
)

Functions

func Version

func Version() string

currently gostagram version

Types

type BaseMediaCarousel

type BaseMediaCarousel struct {
	Type string

	UserInPhoto []struct {
		User User

		Position struct {
			X int
			Y int
		}
	} `mapstructure:"user_in_photo"`
}

Carousel resource can have both image and video resources with it, those resources base attributes are with are in BaseMediaCarousel struct.

type BaseMediaResource

type BaseMediaResource struct {
	Id          string
	Type        string
	Link        string
	Filter      string
	CreatedTime string `mapstructure:"created_time"`

	User         User
	UserHasLiked bool `mapstructure:"user_has_liked"`
	Attribution  interface{}
	Tags         []string

	UserInPhoto []struct {
		User User

		Position struct {
			X int
			Y int
		}
	} `mapstructure:"user_in_photo"`

	Comments struct {
		Count int
	}

	Caption struct {
		From        User
		Id          string
		Text        string
		CreatedTime string
	}

	Likes struct {
		Count int
	}

	Images struct {
		Thumbnail          Image
		LowResolution      Image `mapstructure:"low_resolution"`
		StandardResolution Image `mapstructure:"standard_resolution"`
	}

	Location struct {
		Id            string
		Name          string
		Latitude      float64
		Longitude     float64
		StreetAddress string `mapstructure:"street_address"`
	}
}

BaseMediaResource represent all attributes that all media resources may has.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Instagram client.

Example

prints current user id, username and fullname.

client := NewClient("access_token")
user, err := client.GetCurrentUser()

if err != nil {
	fmt.Println(err)
} else {
	fmt.Println(user.Id)
	fmt.Println(user.Username)
	fmt.Println(user.FullName)
}
Output:

Example (Secure)

prints instagram tags with golang query

client := NewClient("access_token")
client.SetSignedRequest(true)
client.SetClientSecret("client secret")

tags, err := client.SearchTags("golang")

if err != nil {
	fmt.Println(err)
} else {
	for _, tag := range tags {
		fmt.Println("Tag name: ", tag.Name)
	}
}
Output:

func NewClient

func NewClient(access_token string) *Client

func (Client) ApproveUserById

func (c Client) ApproveUserById(user_id string) (*Relationship, error)

func (Client) BlockUserById

func (c Client) BlockUserById(user_id string) (*Relationship, error)

func (Client) CreateSubscription

func (c Client) CreateSubscription() error

func (Client) DeleteMediaComment

func (c Client) DeleteMediaComment(media_id, comment_id string) error

Delete a comment from a media resource for more information about it, go to https://www.instagram.com/developer/endpoints/comments/#delete_media_comments

func (Client) DeleteMediaLike

func (c Client) DeleteMediaLike(media_id string) error

Delete a media resource, with a respective id, for more information about it, go to https://www.instagram.com/developer/endpoints/likes/#delete_likes

func (Client) DeleteSubscription

func (c Client) DeleteSubscription() error

func (Client) FollowUserById

func (c Client) FollowUserById(user_id string) (*Relationship, error)

func (Client) GetCurrentUser

func (c Client) GetCurrentUser() (*UserDetailed, error)

Get current logged user data, for more information go to https://www.instagram.com/developer/endpoints/users/#get_users_self

func (Client) GetCurrentUserFollowedBy

func (c Client) GetCurrentUserFollowedBy() ([]*User, error)

Get a list of users, that current user is followed, for more information go to https://www.instagram.com/developer/endpoints/relationships/#get_users_followed_by

func (Client) GetCurrentUserFollows

func (c Client) GetCurrentUserFollows() ([]*User, error)

Get a list of users that current user follows, for more information go to https://www.instagram.com/developer/endpoints/relationships/#get_users_follows

func (Client) GetCurrentUserMediaLiked

func (c Client) GetCurrentUserMediaLiked(max_like_id string, parameters Parameters) ([]*Media, error)

Get the recent media liked by the current user, for more information aboit it, go to https://www.instagram.com/developer/endpoints/users/#get_users_feed_liked

func (Client) GetCurrentUserRecentMedia

func (c Client) GetCurrentUserRecentMedia(params Parameters) ([]*Media, error)

Get current user media resources and how many resources want to return.

func (Client) GetCurrentUserRelationship

func (c Client) GetCurrentUserRelationship(user_id string) (*Relationship, error)

Check current user relationship with other user by it's id, for more information about it, go to https://www.instagram.com/developer/endpoints/relationships/#get_relationship

func (Client) GetCurrentUserRequestedBy

func (c Client) GetCurrentUserRequestedBy() ([]*User, error)

Get a list of users who have requested this user's permission to follow, for more information go to https://www.instagram.com/developer/endpoints/relationships/#get_incoming_requests

func (Client) GetLocationById

func (c Client) GetLocationById(location_id string) (*Location, error)

Get an especific location by a respective id, for more information about it, go to https://www.instagram.com/developer/endpoints/locations/#get_locations

func (Client) GetMediaById

func (c Client) GetMediaById(media_id string) (*Media, error)

Get media resource by id, for more information about it, go to https://www.instagram.com/developer/endpoints/media/#get_media

func (Client) GetMediaByShortcode

func (c Client) GetMediaByShortcode(short_code string) (*Media, error)

Get media resouce by its shortcode, for more information about it, go to https://www.instagram.com/developer/endpoints/media/#get_media_by_shortcode

func (Client) GetMediaComments

func (c Client) GetMediaComments(media_id string) ([]*Comment, error)

Get all comments from a media resource, for more information about it, go to https://www.instagram.com/developer/endpoints/comments/#get_media_comments

func (Client) GetMediaLikes

func (c Client) GetMediaLikes(media_id string) ([]*User, error)

Get 'likes' from media resource with the respective id, for more information about it, go to https://www.instagram.com/developer/endpoints/likes/#get_media_likes

func (Client) GetRecentMediaLocation

func (c Client) GetRecentMediaLocation(location_id string, params Parameters) ([]*Media, error)

Get media resources from a respective location id, for more information about it, go to https://www.instagram.com/developer/endpoints/locations/#get_locations_media_recent

func (Client) GetRecentMediaTaggedByTagName

func (c Client) GetRecentMediaTaggedByTagName(tagname string, params Parameters) ([]*Media, error)

Get media resources that has hashtags equal to 'tagname', for more information about it, go to https://www.instagram.com/developer/endpoints/tags/#get_tags_media_recent

func (Client) GetTagByName

func (c Client) GetTagByName(tagname string) (*Tag, error)

Get tags(name and how many times was use it), by name for more information about it, go to https://www.instagram.com/developer/endpoints/tags/#get_tags

func (Client) GetUser

func (c Client) GetUser(id string) (*UserDetailed, error)

Get other user data, got more information go to https://www.instagram.com/developer/endpoints/users/#get_users

func (Client) GetUserMedia

func (c Client) GetUserMedia(user_id string, params Parameters) ([]*Media, error)

Get media resources from respective user_id, for more information about it, go to https://www.instagram.com/developer/endpoints/users/#get_users_media_recent

func (Client) IgnoreUserById

func (c Client) IgnoreUserById(user_id string) (*Relationship, error)

func (Client) ListSubscription

func (c Client) ListSubscription() error

func (Client) PostMediaComment

func (c Client) PostMediaComment(text, media_id string) error

To post a comment in a media resource, we need to follow some instagram rules, you can find them at https://www.instagram.com/developer/endpoints/comments/#post_media_comments.

func (Client) PostMediaLike

func (c Client) PostMediaLike(media_id string) error

Do like a media resource, with a respective id, for more information about it, go to https://www.instagram.com/developer/endpoints/likes/#post_likes

func (Client) SearchLocations

func (c Client) SearchLocations(latitude, longitude string, params Parameters) ([]*Location, error)

Search locations by its latitude, longitude, distance and facebook places, for more information about it, go to https://www.instagram.com/developer/endpoints/locations/#get_locations_search

func (Client) SearchMedia

func (c Client) SearchMedia(lat, long string, params Parameters) ([]*Media, error)

Get media resouces by latitude, longitude and distance, for more information about it, go to https://www.instagram.com/developer/endpoints/media/#get_media_search

func (Client) SearchTags

func (c Client) SearchTags(query string) ([]*Tag, error)

Search tags by a query, for more information about it, go to https://www.instagram.com/developer/endpoints/tags/#get_tags_search

func (Client) SearchUsers

func (c Client) SearchUsers(query string, parameters Parameters) ([]*User, error)

get a list of users from the query, for more information go to https://www.instagram.com/developer/endpoints/users/#get_users_search

func (*Client) SetClientId

func (c *Client) SetClientId(id string)

func (*Client) SetClientSecret

func (c *Client) SetClientSecret(cs string)

func (*Client) SetSignedRequest

func (c *Client) SetSignedRequest(sr bool)

func (Client) UnBlockUserById

func (c Client) UnBlockUserById(user_id string) (*Relationship, error)

func (Client) UnFollowUserById

func (c Client) UnFollowUserById(user_id string) (*Relationship, error)

type Comment

type Comment struct {
	From        User
	Id          string
	Text        string
	CreatedTime string `mapstructure:"created_time"`
}

Media resource comment representation.

type Image

type Image struct {
	Url    string
	Width  int
	Height int
}

type Location

type Location struct {
	Id        string
	Name      string
	Latitude  float64
	Longitude float64
}

type Media

type Media interface {
	MediaType() MediaType
}

Media is a generic interface that represents all valid instagram media resources (Images, videos and carousel images).

type MediaCarousel

type MediaCarousel struct {
	BaseMediaResource `mapstructure:",squash"`

	CarouselMedia []Media
}

MediaCarousel struct represents an Image resource that instagram endpoint returns.

func (MediaCarousel) MediaType

func (mi MediaCarousel) MediaType() MediaType

type MediaCarouselImage

type MediaCarouselImage struct {
	BaseMediaCarousel `mapstructure:",squash"`

	Images struct {
		Thumbnail          Image
		LowResolution      Image `mapstructure:"low_resolution"`
		StandardResolution Image `mapstructure:"standard_resolution"`
	}
}

func (MediaCarouselImage) MediaType

func (mi MediaCarouselImage) MediaType() MediaType

type MediaCarouselVideo

type MediaCarouselVideo struct {
	BaseMediaCarousel `mapstructure:",squash"`

	Videos struct {
		LowResolution      VideoResolution `mapstructure:"low_resolution"`
		LowBandwidth       VideoResolution `mapstructure:"low_bandwidth"`
		StandardResolution VideoResolution `mapstructure:"standard_resolution"`
	}
}

func (MediaCarouselVideo) MediaType

func (mi MediaCarouselVideo) MediaType() MediaType

type MediaImage

type MediaImage struct {
	BaseMediaResource `mapstructure:",squash"`
}

MediaImage struct represents an Image resource that instagram endpoint returns.

func (MediaImage) MediaType

func (mi MediaImage) MediaType() MediaType

type MediaType

type MediaType uint8

Represents every media file's type, normaly used to differentiate video, image and carousel resources from a Media interface array ([]Media).

func (MediaType) IsCarousel

func (mt MediaType) IsCarousel() bool

func (MediaType) IsImage

func (mt MediaType) IsImage() bool

func (MediaType) IsVideo

func (mt MediaType) IsVideo() bool

type MediaVideo

type MediaVideo struct {
	BaseMediaResource `mapstructure:",squash"`

	Videos struct {
		LowResolution      VideoResolution `mapstructure:"low_resolution"`
		StandardResolution VideoResolution `mapstructure:"standard_resolution"`
	}
}

MediaVideo struct represents an Image resource that instagram endpoint returns.

func (MediaVideo) MediaType

func (mi MediaVideo) MediaType() MediaType

type Parameters

type Parameters map[string]string

type Relationship

type Relationship struct {
	OutgoingStatus string `mapstructure:"outgoing_status"`
	IncomingStatus string `mapstructure:"incoming_status"`
}

Relationship struct represent relationship status with another user.

func (Relationship) BlockedByYou

func (r Relationship) BlockedByYou() bool

check if current user was blocked by other user.

func (Relationship) FollowedBy

func (r Relationship) FollowedBy() bool

check if current user was followed by other user

func (Relationship) Follows

func (r Relationship) Follows() bool

check if current user follows other user

func (Relationship) Requested

func (r Relationship) Requested() bool

check if current user send a request to follow other user.

func (Relationship) RequestedBy

func (r Relationship) RequestedBy() bool

check if current user was requested by other user to accept the follow.

type Tag

type Tag struct {
	Name       string
	MediaCount int `mapstructure:"media_count"`
}

Tag struct represent instagram hastag representation.

type User

type User struct {
	Id             string
	Type           string
	Username       string
	LastName       string `mapstructure:"last_name"`
	FirstName      string `mapstructure:"first_name"`
	ProfilePicture string `mapstructure:"profile_picture"`
}

User struct represents main user information, most of the time, returned by comments or media metadata.

type UserDetailed

type UserDetailed struct {
	Id             string
	Bio            string
	Website        string
	Username       string
	FullName       string `mapstructure:"full_name"`
	ProfilePicture string `mapstructure:"profile_picture"`

	Counts struct {
		Media      int
		Follows    int
		FollowedBy int `mapstructure:"followed_by"`
	}
}

UserDetailed struct represents user profile information.

type VideoResolution

type VideoResolution struct {
	Url    string
	Width  int
	Height int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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