instago

package module
v0.0.0-...-9bc98fc Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2013 License: Apache-2.0 Imports: 9 Imported by: 0

README

#instago

instago is a simple and easy to use Go library that simplifies communicating with the Instagram JSON API. I currently only intend for it to use the public functions of the Instagram API that don't require user authentication, however I support some of them if you have an access token.

To use this library, clone the repo into your Go workspace and have a look at some of the demo apps. You'll need to build and install the instago package and get an Instagram API developer ID. Paste your client ID in a file called config.txt in the demos folder to run the samples.

Implemented methods:

  • /tags/tagname/media/recent
  • /tags/tagname
  • /tags/search
  • /users/user-id
  • /users/search
  • /media/media-id
  • /media/popular
  • /media/search
  • /locations/location-id
  • /locations/location-id/media/recent
  • /locations/search/

Implemented methods that require OAuth (not demoed):

  • /users/user-id/media/recent
  • /users/self/feed
  • /users/self/media/liked

##License It's Apache. See the LICENSE file.

Documentation

Overview

Instago provides a simple library that makes it easier to interact with Instagram through their API directly from Go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Download

func Download(url, saveFile string)

Download a file from the given URL and save it to the given file Note that the Instagram API encourages you to take into account the IP of Instagram users, so you shouldn't download user's images with this

func JSONArray

func JSONArray(data interface{}) []interface{}

Checks to see if an interface is an array, and if not return an empty array

func JSONFloat

func JSONFloat(data interface{}) float64

Check to see if an interface is a float(64) and if it is not it will return 0

func JSONInt

func JSONInt(data interface{}) int

Check to see if an interface is an int and if it is not it will return 0

func JSONString

func JSONString(data interface{}) string

Check to see if an interface is a string and if it is not, return an empty string

func JSONStringArray

func JSONStringArray(data interface{}) []string

Checks to see if an interface is an array of strings, and if not return an empty string array

Types

type Image

type Image struct {
	Filter             string
	Tags               []string
	Link               string
	LowResolution      string
	Thumbnail          string
	StandardResolution string
	User               string
	UserID             string
	Name               string
	Caption            string
	CreationTime       time.Time
	ID                 string
	Likes              int
	Comments           int
	Location           Location
}

Represents an image response from Instagram's servers including key details about the image. Comments are currently not included.

func ImageFromAPI

func ImageFromAPI(data JSON) Image

This will take API a JSON object that includes the details for an image and puts it into the Go data structure for Images.

data: a JSON object that represents an image

type InstagramAPI

type InstagramAPI struct {
	ClientID    string
	AccessToken string
}

The InstagramAPI object stores your credentials. You can obtain a ClientID from http://instagram.com/developer. If you want to interact directly with a user's account you can also obtain an AccessToken through OAuth, however this library currently doesn't support obtaining the ClientID. If the AccessToken is present the ClientID will be ignored (even if the request fails). You should create an InstagramAPI struct with at least one of these values

func (InstagramAPI) DoRequest

func (api InstagramAPI) DoRequest(endpoint string, params map[string]string) JSON

This will does all GET requests (all Instagram API requests that do not require authentication are GET requests anyway). It returns the JSON object in case of success or an empty object in case of failure

endpoint: The api request that you want to do on Instagram

params: The parameters you may want to add

func (InstagramAPI) Feed

func (api InstagramAPI) Feed(before, after string, max int) []Image

Gets the current user's feed (requires OAuth)

before: (optional = "") posts before a certain ID

after: (optional = "") posts after a certain ID

max: (optional = 0) the greatest number of images to return

func (InstagramAPI) GenericImageListRequest

func (api InstagramAPI) GenericImageListRequest(endPoint, before, after string, max int) []Image

Many queries to Instagram's API simply return a list of images (tag, user, location, etc) so this function handles the request to simplify things a little. Note that Intago functions provide wrappers around this function so you need not call it, however it is exported in case Instagram adds to their API in the future and you want to add to this library

endPoint: The API endpoint, such as /tags/tag/media/recent

before: (optional) Search for images before this image ID

after: (optional) Search for images after this image ID

max: (optional) The great number of images to return (there is an imposed limit on this)

func (InstagramAPI) GetURLForRequest

func (api InstagramAPI) GetURLForRequest(endpoint string, params map[string]string) string

This function will build the request URL so that you can add extra parameters to requests.

endpoint: The API request that you are planning on doing; such as tags/{x}/media/recent

params: A map of the extra parameters (aside from client_id) that you want to add to the query

func (InstagramAPI) Liked

func (api InstagramAPI) Liked(max int, before string) []Image

Gets the posts like by the current user (requires OAuth)

max: (optional = 0) the greatest number of posts to return

before: (optional = 0) posts liked before a certain image ID

func (InstagramAPI) Location

func (api InstagramAPI) Location(locationId string) Location

Gets basic information such as name and coordinates for a location

locationId: The id of a location to lookup

func (InstagramAPI) LocationPosts

func (api InstagramAPI) LocationPosts(locationId, beforePost, afterPost string) []Image

Gets media posted from that location

locationId: The id of the location

beforePost: (optional = "") posts before this ID

afterPost: (optional = "") posts after this ID

func (InstagramAPI) LocationSearch

func (api InstagramAPI) LocationSearch(lat, lng, distance float64) []Image

Gets a list of media posted from a certain location recently. N.B. This seems a bit unreliable...

lat: The latitude to search near

long: The longitude to search near

distance: (optional = 0) The number of meters to search within

func (InstagramAPI) LocationsNear

func (api InstagramAPI) LocationsNear(lat, long, distance float64) []Location

Gets a list of locations near a give latitude/longitude within a certain distance

lat: The latitude to search near

long: The longitude to search near

distance: (optional = 0) The number of meters to search within

func (InstagramAPI) Media

func (api InstagramAPI) Media(mediaId string) Image

Gets details for media with the given ID

mediaId: A string representing the ID of the image to get info on

func (InstagramAPI) Popular

func (api InstagramAPI) Popular() []Image

Gets a list of popular media at the moment

func (InstagramAPI) RecentPostsByUser

func (api InstagramAPI) RecentPostsByUser(userId string, max int, before, after string) []Image

Will return an array of recently posted images by a user. Requires OAuth

userId: string representing the user

max: the greatest number of images to return

before: (optional = "") posts before a certain ID

after: (optional = "") posts after a certain ID

func (InstagramAPI) SearchUsers

func (api InstagramAPI) SearchUsers(query string, max int) []User

Query the users on Instagram and get a list of them back

query: The description such as 'jack' or 'thomas' to search for

max: (optional, default = 0) the number of users to return

func (InstagramAPI) TagInfo

func (api InstagramAPI) TagInfo(tag string) Tag

Gets the total number of images on Instagram with a given tag

tag: a string that represents the tag that you want to search for

func (InstagramAPI) TagRecent

func (api InstagramAPI) TagRecent(tag, before, after string) []Image

Gets all (16) recent photos with the given tag

tag: The tag (don't include the # hash) that you want to fetch

before: (optional - use "") find photos posted before this ID (use Image.ID)

after: (optional - use "") find photos posted after this ID (use Image.ID)

func (InstagramAPI) TagSearch

func (api InstagramAPI) TagSearch(tag string) []Tag

Will fetch the tag along with similar tags from Instagram so you can see the number of images with that tag

tag: a string that represents the tag you want to search for

func (InstagramAPI) UserDetail

func (api InstagramAPI) UserDetail(userID string) User

Gets basic information about a given user

userID: a string representing the ID (not the username) of a given user

type JSON

type JSON map[string]interface{}

The JSON type can be used when you do not directly want to parse JSON data into a Go struct, or when you are dealing with object types that are unknown or constantly changing. The API uses this because a) The structure of some Instagram API requests adds a lot of additional unnecessary data that ought not be in the final Go response.

func JSONObject

func JSONObject(data interface{}) JSON

Checks to see if an object is a JSON object and if not, return an empty object

func JSONObjectArray

func JSONObjectArray(data interface{}) []JSON

Check to see if it is an array of objects and if not return an empty JSON object array

func (JSON) Array

func (json JSON) Array(key string) []interface{}

Utility wrapper around JSONArray

func (JSON) Float

func (json JSON) Float(key string) float64

Utility wrapper around JSONFloat

func (JSON) Int

func (json JSON) Int(key string) int

Utility wrapper around JSONInt

func (JSON) Object

func (json JSON) Object(key string) JSON

Utility wrapper around JSONObject

func (JSON) ObjectArray

func (json JSON) ObjectArray(key string) []JSON

Utility wrapper around JSONObjectArray

func (JSON) String

func (json JSON) String(key string) string

Utility wrapper around JSONString

func (JSON) StringArray

func (json JSON) StringArray(key string) []string

Utility wrapper around JSONStringArray

type Location

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

As well as being able to look near a specific longitude/latitude, you can also look at a specific location, such as a bar, museum, company, etc. This type represents the responses from Instagram's servers.

func LocationFromAPI

func LocationFromAPI(location JSON) Location

Takes a generic location API JSON response and returns a Location

type Tag

type Tag struct {
	Tag        string
	MediaCount int
}

Represents a tag and the total number of images with that tag

type User

type User struct {
	ID             string
	Username       string
	FullName       string
	ProfilePicture string
	Bio            string
	Website        string
	TotalImages    int
	TotalFollows   int
	TotalFollowers int
}

Represents a user response from Instagram's servers. This may come from an image, comment or directly from a user request (N.B. these kind of requests require OAuth)

func UserFromAPI

func UserFromAPI(data JSON) User

This will take an API JSON response that includes some user detail and return a more usable Go User object

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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