instagram

package
v0.0.0-...-e09b900 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2015 License: BSD-2-Clause Imports: 11 Imported by: 1

Documentation

Overview

Package instagram provides a client for using the Instagram API.

Access different parts of the Instagram API using the various services on a Instagram Client (second parameter is access token that likely you'll need to access most of Instagram endpoints):

client := instagram.NewClient(nil)

You can then optionally set ClientID, ClientSecret and AccessToken:

client.ClientID = "8f2c0ad697ea4094beb2b1753b7cde9c"

With client object set, you can call Instagram endpoints:

// Gets the most recent media published by a user with id "3"
media, next, err := client.Users.RecentMedia("3", nil)

Set optional parameters for an API method by passing an Parameters object.

// Gets user's feed.
opt := &instagram.Parameters{Count: 3}
media, next, err := client.Users.RecentMedia("3", opt)

The full Instagram API is documented at http://instagram.com/developer/endpoints/.

Index

Constants

View Source
const (
	// LibraryVersion represents this library version
	LibraryVersion = "0.5"

	// BaseURL represents Instagram API base URL
	BaseURL = "https://api.instagram.com/v1/"

	// UserAgent represents this client User-Agent
	UserAgent = "github.com/carbocation/go-instagram v" + LibraryVersion
)

Variables

This section is empty.

Functions

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse checks the API response for error, and returns it if present. A response is considered an error if it has non StatusOK code.

func ServeInstagramRealtimeSubscribe

func ServeInstagramRealtimeSubscribe(w http.ResponseWriter, r *http.Request)

ServeInstagramRealtimeSubscribe - an example RealTimeSubscribe ResponseWriter. This can be plugged directly into any standard http server. Note, however, that this particular implementation does no checking that the verifyToken is correct.

Types

type Client

type Client struct {

	// Base URL for API requests.
	BaseURL *url.URL

	// UserAgent agent used when communicating with Instagram API.
	UserAgent string

	// Application client_id
	ClientID string

	// Application client_secret
	ClientSecret string

	// Authenticated user's access_token
	AccessToken string

	// For Authenticated endpoints, using X-Forwarded-For
	// increases events per hour permitted by Instagram
	// This value should, if not nil, be the value of
	// a user's IP address. See
	// http://instagram.com/developer/restrict-api-requests/
	// for additional detail
	XInstaForwardedFor string

	// Services used for talking to different parts of the API.
	Users         *UsersService
	Relationships *RelationshipsService
	Media         *MediaService
	Comments      *CommentsService
	Likes         *LikesService
	Tags          *TagsService
	Locations     *LocationsService
	Geographies   *GeographiesService
	Realtime      *RealtimeService

	// Temporary Response
	Response *Response
	// contains filtered or unexported fields
}

A Client manages communication with the Instagram API.

func NewClient

func NewClient(httpClient *http.Client) *Client

NewClient returns a new Instagram API client. if a nil httpClient is provided, http.DefaultClient will be used.

func (*Client) ComputeXInstaForwardedFor

func (c *Client) ComputeXInstaForwardedFor() string

ComputeXInstaForwardedFor returns value for X-Insta-Forwarded-For header

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) (*http.Response, error)

Do sends an API request and returns the API response. The API response is decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred.

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body string) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, in which case it is resolved relative to the BaseURL of the Client. Relative URLs should always be specified without a preceding slash. If specified

type Comment

type Comment struct {
	CreatedTime int64  `json:"created_time,string,omitempty"`
	Text        string `json:"text,omitempty"`
	From        *User  `json:"from,omitempty"`
	ID          string `json:"id,omitempty"`
}

Comment represents a comment on Instagram's media.

type CommentsService

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

CommentsService handles communication with the comments related methods of the Instagram API.

Instagram API docs: http://instagram.com/developer/endpoints/comments/

func (*CommentsService) Add

func (s *CommentsService) Add(mediaID string, text []string) error

Add a comment on a media.

Instagram API docs: http://instagram.com/developer/endpoints/comments/#post_media_comments

func (*CommentsService) Delete

func (s *CommentsService) Delete(mediaID, commentID string) error

Delete a comment either on the authenticated user's media or authored by the authenticated user.

Instagram API docs: http://instagram.com/developer/endpoints/comments/#delete_media_comments

func (*CommentsService) MediaComments

func (s *CommentsService) MediaComments(mediaID string) ([]Comment, error)

MediaComments gets a full list of comments on a media.

Instagram API docs: http://instagram.com/developer/endpoints/comments/#get_media_comments

type Error

type Error ResponseMeta

Error represents an error recieved from instagram

func (*Error) Error

func (err *Error) Error() string

Error makes the Error suitable for the error interface

type ErrorResponse

type ErrorResponse Response

ErrorResponse represents a Response which contains an error

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type GeographiesService

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

GeographiesService handles communication with the geographies related methods of the Instagram API.

Instagram API docs: http://instagram.com/developer/endpoints/geographies/

func (*GeographiesService) RecentMedia

func (s *GeographiesService) RecentMedia(geoID string, opt *Parameters) ([]Media, *ResponsePagination, error)

RecentMedia gets recent media from a geography subscription that created by real-time subscriptions.

Instagram API docs: http://instagram.com/developer/endpoints/geographies/#get_geographies_media_recent

type LikesService

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

LikesService handles communication with the likes related methods of the Instagram API.

Instagram API docs: http://instagram.com/developer/endpoints/likes/

func (*LikesService) Like

func (s *LikesService) Like(mediaID string) error

Like a media.

Instagram API docs: http://instagram.com/developer/endpoints/likes/#post_likes

func (*LikesService) MediaLikes

func (s *LikesService) MediaLikes(mediaID string) ([]User, error)

MediaLikes gets a list of users who have liked mediaID.

Instagram API docs: http://instagram.com/developer/endpoints/likes/#get_media_likes

func (*LikesService) Unlike

func (s *LikesService) Unlike(mediaID string) error

Unlike a media.

Instagram API docs: http://instagram.com/developer/endpoints/likes/#delete_likes

type Location

type Location struct {
	ID        string  `json:"id,omitempty"`
	Name      string  `json:"name,omitempty"`
	Latitude  float64 `json:"latitude,omitempty"`
	Longitude float64 `json:"longitude,omitempty"`
}

Location represents information about a location.

type LocationsService

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

LocationsService handles communication with the locations related methods of the Instagram API.

Instagram API docs: http://instagram.com/developer/endpoints/locations/

func (*LocationsService) Get

func (s *LocationsService) Get(locationID string) (*Location, error)

Get information about a location.

Instagram API docs: http://instagram.com/developer/endpoints/locations/#get_locations

func (*LocationsService) RecentMedia

func (s *LocationsService) RecentMedia(locationID string, opt *Parameters) ([]Media, *ResponsePagination, error)

RecentMedia gets a list of recent media from a given location.

Instagram API docs: http://instagram.com/developer/endpoints/locations/#get_locations_media_recent

func (*LocationsService) Search

func (s *LocationsService) Search(lat, lng float64, opt *Parameters) ([]Location, error)

Search for a location by geographic coordinate.

Instagram API docs: http://instagram.com/developer/endpoints/locations/#get_locations_search

type Media

type Media struct {
	Type         string         `json:"type,omitempty"`
	UsersInPhoto []*UserInPhoto `json:"users_in_photo,omitempty"`
	Filter       string         `json:"filter,omitempty"`
	Tags         []string       `json:"tags,omitempty"`
	Comments     *MediaComments `json:"comments,omitempty"`
	Caption      *MediaCaption  `json:"caption,omitempty"`
	Likes        *MediaLikes    `json:"likes,omitempty"`
	Link         string         `json:"link,omitempty"`
	User         *User          `json:"user,omitempty"`
	UserHasLiked bool           `json:"user_has_liked,omitempty"`
	CreatedTime  int64          `json:"created_time,string,omitempty"`
	Images       *MediaImages   `json:"images,omitempty"`
	Videos       *MediaVideos   `json:"videos,omitempty"`
	ID           string         `json:"id,omitempty"`
	Location     *MediaLocation `json:"location,omitempty"`
}

Media represents a single media (image or video) on Instagram.

type MediaCaption

type MediaCaption struct {
	CreatedTime int64  `json:"created_time,string,omitempty"`
	Text        string `json:"text,omitempty"`
	From        *User  `json:"from,omitempty"`
	ID          string `json:"id,omitempty"`
}

MediaCaption represents caption on Instagram's media.

type MediaComments

type MediaComments struct {
	Count int        `json:"count,omitempty"`
	Data  []*Comment `json:"data,omitempty"`
}

MediaComments represents comments on Instagram's media.

type MediaImage

type MediaImage struct {
	URL    string `json:"url,omitempty"`
	Width  int    `json:"width,omitempty"`
	Height int    `json:"height,omitempty"`
}

MediaImage represents Instagram media with type image.

type MediaImages

type MediaImages struct {
	LowResolution      *MediaImage `json:"low_resolution,omitempty"`
	Thumbnail          *MediaImage `json:"thumbnail,omitempty"`
	StandardResolution *MediaImage `json:"standard_resolution,omitempty"`
}

MediaImages represents MediaImage with various resolutions.

type MediaLikes

type MediaLikes struct {
	Count int `json:"count,omitempty"`
	Data  []*User
}

MediaLikes represents likes on Instagram's media.

type MediaLocation

type MediaLocation struct {
	ID        int     `json:"id,omitempty"`
	Name      string  `json:"name,omitempty"`
	Latitude  float64 `json:"latitude,omitempty"`
	Longitude float64 `json:"longitude,omitempty"`
}

MediaLocation represents information about a location.

There's Location type under LocationsService, the different is the ID type. I've reported this inconsistency to Instagram https://groups.google.com/forum/#!topic/instagram-api-developers/Fty5lOsOGEg

type MediaService

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

MediaService handles communication with the media related methods of the Instagram API.

Instagram API docs: http://instagram.com/developer/endpoints/media/

func (*MediaService) Get

func (s *MediaService) Get(mediaID string) (*Media, error)

Get information about a media object.

Instagram API docs: http://instagram.com/developer/endpoints/media/#get_media

func (*MediaService) Popular

func (s *MediaService) Popular() ([]Media, *ResponsePagination, error)

Popular gets a list of what media is most popular at the moment.

Instagram API docs: http://instagram.com/developer/endpoints/media/#get_media_popular

func (*MediaService) Search

func (s *MediaService) Search(opt *Parameters) ([]Media, *ResponsePagination, error)

Search return search results for media in a given area.

http://instagram.com/developer/endpoints/media/#get_media_search

type MediaVideo

type MediaVideo struct {
	URL    string `json:"url,omitempty"`
	Width  int    `json:"width,omitempty"`
	Height int    `json:"height,omitempty"`
}

MediaVideo represents Instagram media with type video.

type MediaVideos

type MediaVideos struct {
	LowResolution      *MediaVideo `json:"low_resolution,omitempty"`
	StandardResolution *MediaVideo `json:"standard_resolution,omitempty"`
}

MediaVideos represents MediaVideo with various resolutions.

type Parameters

type Parameters struct {
	Count        uint64
	MinID        string
	MaxID        string
	MinTimestamp int64
	MaxTimestamp int64
	Lat          float64
	Lng          float64
	Distance     float64
}

Parameters specifies the optional parameters to various service's methods.

type Ratelimit

type Ratelimit struct {
	// Total number of possible calls per hour
	Limit int

	// How many calls are left for this particular token or client ID
	Remaining int
}

Ratelimit specifies API calls limit found in HTTP headers.

type Realtime

type Realtime struct {
	ID          string `json:"id,omitempty"`
	Type        string `json:"type,omitempty"`
	Object      string `json:"object,omitempty"`
	ObjectID    string `json:"object_id,omitempty"`
	Aspect      string `json:"aspect,omitempty"`
	CallbackURL string `json:"callback_url,omitempty"`
}

Realtime represents a realtime subscription on Instagram's service.

type RealtimeResponse

type RealtimeResponse struct {
	SubscriptionID int64  `json:"subscription_id,omitempty"`
	Object         string `json:"object,omitempty"`
	ObjectID       string `json:"object_id,omitempty"`
	ChangedAspect  string `json:"changed_aspect,omitempty"`
	Time           int64  `json:"time,omitempty"`
}

RealtimeResponse represents JSON structure

type RealtimeService

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

RealtimeService has client info

func (*RealtimeService) DeleteAllSubscriptions

func (s *RealtimeService) DeleteAllSubscriptions() (*Realtime, error)

DeleteAllSubscriptions deletes all active subscriptions for an account.

Instagram API docs: http://instagram.com/developer/realtime/

func (*RealtimeService) ListSubscriptions

func (s *RealtimeService) ListSubscriptions() ([]Realtime, error)

ListSubscriptions ists the realtime subscriptions that are already active for your account

func (*RealtimeService) SubscribeToGeography

func (s *RealtimeService) SubscribeToGeography(lat, lng string, radius int, callbackURL, verifyToken string) (*Realtime, error)

SubscribeToGeography initiates the subscription to realtime updates about geography `lat,lng,radius`

Instagram API docs: http://instagram.com/developer/realtime/

func (*RealtimeService) SubscribeToLocation

func (s *RealtimeService) SubscribeToLocation(locationId, callbackURL, verifyToken string) (*Realtime, error)

SubscribeToLocation initiates the subscription to realtime updates about location `locationId`

Instagram API docs: http://instagram.com/developer/realtime/

func (*RealtimeService) SubscribeToTag

func (s *RealtimeService) SubscribeToTag(tag, callbackURL, verifyToken string) (*Realtime, error)

SubscribeToTag initiates the subscription to realtime updates about tag `tag`

Instagram API docs: http://instagram.com/developer/realtime/

func (*RealtimeService) UnsubscribeFrom

func (s *RealtimeService) UnsubscribeFrom(sid string) (*Realtime, error)

UnsubscribeFrom unsubscribes you from a specific subscription.

Instagram API docs: http://instagram.com/developer/realtime/

type Relationship

type Relationship struct {
	// Current user's relationship to another user. Can be "follows", "requested", or "none".
	OutgoingStatus string `json:"outgoing_status,omitempty"`

	// A user's relationship to current user. Can be "followed_by", "requested_by",
	// "blocked_by_you", or "none".
	IncomingStatus string `json:"incoming_status,omitempty"`

	// Undocumented part of the API, though was stable at least from 2012-2015
	// Informs whether the target user is a private user
	TargetUserIsPrivate bool `json:"target_user_is_private,omitempty"`
}

Relationship represents relationship authenticated user with another user.

type RelationshipsService

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

RelationshipsService handles communication with the user's relationships related methods of the Instagram API.

Instagram API docs: http://instagram.com/developer/endpoints/relationships/

func (*RelationshipsService) Approve

func (s *RelationshipsService) Approve(userID string) (*Relationship, error)

Approve a user.

Instagram API docs: http://instagram.com/developer/endpoints/relationships/#post_relationship

func (*RelationshipsService) Block

func (s *RelationshipsService) Block(userID string) (*Relationship, error)

Block a user.

Instagram API docs: http://instagram.com/developer/endpoints/relationships/#post_relationship

func (*RelationshipsService) Deny

func (s *RelationshipsService) Deny(userID string) (*Relationship, error)

Deny a user.

Instagram API docs: http://instagram.com/developer/endpoints/relationships/#post_relationship

func (*RelationshipsService) Follow

func (s *RelationshipsService) Follow(userID string) (*Relationship, error)

Follow a user.

Instagram API docs: http://instagram.com/developer/endpoints/relationships/#post_relationship

func (*RelationshipsService) FollowedBy

func (s *RelationshipsService) FollowedBy(userID string) ([]User, *ResponsePagination, error)

FollowedBy gets the list of users this user is followed by. If empty string is passed then it refers to `self` or curret authenticated user.

Instagram API docs: http://instagram.com/developer/endpoints/relationships/#get_users_followed_by

func (*RelationshipsService) Follows

func (s *RelationshipsService) Follows(userID string) ([]User, *ResponsePagination, error)

Follows gets the list of users this user follows. If empty string is passed then it refers to `self` or curret authenticated user.

Instagram API docs: http://instagram.com/developer/endpoints/relationships/#get_users_follows

func (*RelationshipsService) Relationship

func (s *RelationshipsService) Relationship(userID string) (*Relationship, error)

Relationship gets information about a relationship to another user.

Instagram API docs: http://instagram.com/developer/endpoints/relationships/#get_relationship

func (*RelationshipsService) RequestedBy

func (s *RelationshipsService) RequestedBy() ([]User, *ResponsePagination, error)

RequestedBy lists the users who have requested this user's permission to follow.

Instagram API docs: http://instagram.com/developer/endpoints/relationships/#get_incoming_requests

func (*RelationshipsService) Unblock

func (s *RelationshipsService) Unblock(userID string) (*Relationship, error)

Unblock a user.

Instagram API docs: http://instagram.com/developer/endpoints/relationships/#post_relationship

func (*RelationshipsService) Unfollow

func (s *RelationshipsService) Unfollow(userID string) (*Relationship, error)

Unfollow a user.

Instagram API docs: http://instagram.com/developer/endpoints/relationships/#post_relationship

type Response

type Response struct {
	Response   *http.Response      // HTTP response
	Meta       *ResponseMeta       `json:"meta,omitempty"`
	Data       interface{}         `json:"data,omitempty"`
	Pagination *ResponsePagination `json:"pagination,omitempty"`
}

Response specifies Instagram's response structure.

Instagram's envelope structure spec: http://instagram.com/developer/endpoints/#structure

func (*Response) GetData

func (r *Response) GetData() interface{}

GetData gets the meat of the response.

func (*Response) GetError

func (r *Response) GetError() error

GetError gets error from meta's response.

func (*Response) GetMeta

func (r *Response) GetMeta() *ResponseMeta

GetMeta gets extra information about the response. If all goes well, only Code key with value 200 is returned. If something goes wrong, ErrorType and ErrorMessage keys are present.

func (*Response) GetPagination

func (r *Response) GetPagination() *ResponsePagination

GetPagination gets pagination information.

func (*Response) GetRatelimit

func (r *Response) GetRatelimit() (Ratelimit, error)

GetRatelimit returns parsed rate limit information from response headers.

func (*Response) NextMaxID

func (r *Response) NextMaxID() string

NextMaxID gets MaxID parameter that can be passed for next request.

func (*Response) NextURL

func (r *Response) NextURL() string

NextURL gets next url which represents URL for next set of data.

type ResponseMeta

type ResponseMeta struct {
	ErrorType    string `json:"error_type,omitempty"`
	Code         int    `json:"code,omitempty"`
	ErrorMessage string `json:"error_message,omitempty"`
}

ResponseMeta represents information about the response. If all goes well, only a Code key with value 200 will present. However, sometimes things go wrong, and in that case ErrorType and ErrorMessage are present.

type ResponsePagination

type ResponsePagination struct {
	NextURL   string `json:"next_url,omitempty"`
	NextMaxID string `json:"next_max_id,omitempty"`
}

ResponsePagination represents information to get access to more data in any request for sequential data.

type Tag

type Tag struct {
	MediaCount int    `json:"media_count,omitempty"`
	Name       string `json:"name,omitempty"`
}

Tag represents information about a tag object.

type TagsService

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

TagsService handles communication with the tag related methods of the Instagram API.

Instagram API docs: http://instagram.com/developer/endpoints/tags/

func (*TagsService) Get

func (s *TagsService) Get(tagName string) (*Tag, error)

Get information aout a tag object.

Instagram API docs: http://instagram.com/developer/endpoints/tags/#get_tags

func (*TagsService) RecentMedia

func (s *TagsService) RecentMedia(tagName string, opt *Parameters) ([]Media, *ResponsePagination, error)

RecentMedia Get a list of recently tagged media.

Instagram API docs: http://instagram.com/developer/endpoints/tags/#get_tags_media_recent

func (*TagsService) Search

func (s *TagsService) Search(q string) ([]Tag, *ResponsePagination, error)

Search for tags by name.

Instagram API docs: http://instagram.com/developer/endpoints/tags/#get_tags_search

type User

type User struct {
	ID             string     `json:"id,omitempty"`
	Username       string     `json:"username,omitempty"`
	FullName       string     `json:"full_name,omitempty"`
	ProfilePicture string     `json:"profile_picture,omitempty"`
	Bio            string     `json:"bio,omitempty"`
	Website        string     `json:"website,omitempty"`
	Counts         *UserCount `json:"counts,omitempty"`
}

User represents Instagram user.

type UserCount

type UserCount struct {
	Media      int `json:"media,omitempty"`
	Follows    int `json:"follows,omitempty"`
	FollowedBy int `json:"followed_by,omitempty"`
}

UserCount represents stats of a Instagram user.

type UserInPhoto

type UserInPhoto struct {
	User     *User                `json:"user,omitempty"`
	Position *UserInPhotoPosition `json:"position,omitempty"`
}

UserInPhoto represents a single user, with its position, on Instagram photo.

type UserInPhotoPosition

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

UserInPhotoPosition represents position of the user on Instagram photo.

type UsersService

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

UsersService handles communication with the user related methods of the Instagram API.

Instagram API docs: http://instagram.com/developer/endpoints/users/

func (*UsersService) Get

func (s *UsersService) Get(userID string) (*User, error)

Get basic information about a user. Passing the empty string will fetch the authenticated user.

Instagram API docs: http://instagram.com/developer/endpoints/users/#get_users

func (*UsersService) LikedMedia

func (s *UsersService) LikedMedia(opt *Parameters) ([]Media, *ResponsePagination, error)

LikedMedia gets authenticated user's list of media they've liked.

Instagram API docs: http://instagram.com/developer/endpoints/users/#get_users_feed_liked

func (*UsersService) MediaFeed

func (s *UsersService) MediaFeed(opt *Parameters) ([]Media, *ResponsePagination, error)

MediaFeed gets authenticated user's feed.

Instagram API docs: http://instagram.com/developer/endpoints/users/#get_users_feed

func (*UsersService) RecentMedia

func (s *UsersService) RecentMedia(userID string, opt *Parameters) ([]Media, *ResponsePagination, error)

RecentMedia gets the most recent media published by a user.

Instagram API docs: http://instagram.com/developer/endpoints/users/#get_users_media_recent

func (*UsersService) Search

func (s *UsersService) Search(q string, opt *Parameters) ([]User, *ResponsePagination, error)

Search for a user by name.

Instagram API docs: http://instagram.com/developer/endpoints/users/#get_users_search

Jump to

Keyboard shortcuts

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