package module
Version: v0.0.0-...-a1781c8 Latest Latest

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

Go to latest
Published: Feb 13, 2018 License: Unlicense Imports: 9 Imported by: 0


Get Instagram User Media in Go_

.. image:: https://img.shields.io/badge/Language-Go-blue.svg
   :target: https://golang.org/

.. image:: https://godoc.org/github.com/siongui/goigmedia?status.png
   :target: https://godoc.org/github.com/siongui/goigmedia

.. image:: https://api.travis-ci.org/siongui/goigmedia.png?branch=master
   :target: https://travis-ci.org/siongui/goigmedia

.. image:: https://goreportcard.com/badge/github.com/siongui/goigmedia
   :target: https://goreportcard.com/report/github.com/siongui/goigmedia

.. image:: https://img.shields.io/badge/license-Unlicense-blue.svg
   :target: https://raw.githubusercontent.com/siongui/goigmedia/master/UNLICENSE

.. image:: https://img.shields.io/badge/Status-Beta-brightgreen.svg

.. image:: https://img.shields.io/twitter/url/https/github.com/siongui/goigmedia.svg?style=social
   :target: https://twitter.com/intent/tweet?text=Wow:&url=%5Bobject%20Object%5D

Get links of Instagram_ user media (photos and videos) in Go.

Obtain Cookies

The following three values are must to access the Instagram API.

- ``ds_user_id``
- ``sessionid``
- ``csrftoken``

First login to Instagram_ from Chrome browser, and there are two ways to get the
above information:

1. From `Chrome Developer Tools`_: See this `SO answer`_ or `Obtain cookies`_
   section in `instastories-backup`_ repo.

.. image:: https://i.stack.imgur.com/psJLZ.png
   :align: center
   :alt: ds_user_id sessionid csrftoken

2. From Chrome extension: Use EditThisCookie_ or `cookie-txt-export`_ or other
   cookie tools.


Released in public domain. See UNLICENSE_.


.. [1] `GitHub - siongui/goiguserid: Get id of Instagram user in Go <https://github.com/siongui/goiguserid>`_
.. [2] `GitHub - siongui/goigstorylink: Get Links (URL) of Instagram Stories in Go <https://github.com/siongui/goigstorylink>`_
.. [3] `GitHub - siongui/goigfollow: Get Instagram following and followers in Go <https://github.com/siongui/goigfollow>`_
.. [4] `GitHub - siongui/goigstorydl: Download Instagram Stories in Go <https://github.com/siongui/goigstorydl>`_

.. _Go: https://golang.org/
.. _Instagram: https://www.instagram.com/
.. _Chrome Developer Tools: https://developer.chrome.com/devtools
.. _SO answer: https://stackoverflow.com/a/44773079
.. _Obtain cookies: https://github.com/hoschiCZ/instastories-backup#obtain-cookies
.. _instastories-backup: https://github.com/hoschiCZ/instastories-backup
.. _EditThisCookie: https://www.google.com/search?q=EditThisCookie
.. _cookie-txt-export: https://github.com/siongui/cookie-txt-export.go
.. _UNLICENSE: http://unlicense.org/



Package igmedia helps you get all URLs of posts of a specific Instagram user, and also media (photos and videos) links of posts.




This section is empty.


This section is empty.


func GetUserId

func GetUserId(username string) (id string, err error)

Given user name, return id of the user name.


25025320 <nil>

func SetUserAgent

func SetUserAgent(s string)

Set User-Agent header in HTTP requests.


type EdgeMedia

type EdgeMedia struct {
	Typename   string `json:"__typename"`
	Shortcode  string `json:"shortcode"`
	Dimensions struct {
		Height int64 `json:"height"`
		Width  int64 `json:"width"`
	} `json:"dimensions"`
	DisplayUrl       string `json:"display_url"`
	DisplayResources []struct {
		Src          string `json:"src"`
		ConfigWidth  int64  `json:"config_width"`
		ConfigHeight int64  `json:"config_height"`
	} `json:"display_resources"`
	VideoUrl         string `json:"video_url"`
	IsVideo          bool   `json:"is_video"`
	TakenAtTimestamp int64  `json:"taken_at_timestamp"`
	Location         struct {
		Id            string `json:"id"`
		HasPublicPage bool   `json:"has_public_page"`
		Name          string `json:"name"`
		Slug          string `json:"slug"`
	} `json:"location"`
	EdgeSidecarToChildren struct {
		Edges []struct {
			Node EdgeMedia `json:"node"`
		} `json:"edges"`
	} `json:"edge_sidecar_to_children"`

type IGApiManager

type IGApiManager struct {
	// contains filtered or unexported fields

func NewInstagramApiManager

func NewInstagramApiManager(ds_user_id, sessionid, csrftoken string) *IGApiManager

After login to Instagram, you can get the cookies of *ds_user_id*, *sessionid*, *csrftoken* in Chrome Developer Tools. See https://stackoverflow.com/a/44773079 or https://github.com/hoschiCZ/instastories-backup#obtain-cookies

func (*IGApiManager) GetAllPostCode

func (m *IGApiManager) GetAllPostCode(username string) (codes []string, err error)

Given user name, return codes of all posts of the user. TODO: add sleep at the end of forloop. If the number of posts is over 2400, Instagram API will return http response code 429 (Too Many Requests)

func (*IGApiManager) GetPostInfo

func (m *IGApiManager) GetPostInfo(code string) (em EdgeMedia, err error)

Given code of post, return information of the post with login status.

func (*IGApiManager) GetUserInfo

func (m *IGApiManager) GetUserInfo(username string) (ui UserInfo, err error)

Given user name, return information of the user name.

type UserInfo

type UserInfo struct {
	Biography       string `json:"biography"`
	ExternalUrl     string `json:"external_url"`
	FullName        string `json:"full_name"`
	Id              string `json:"id"`
	IsPrivate       bool   `json:"is_private"`
	ProfilePicUrlHd string `json:"profile_pic_url_hd"`
	Username        string `json:"username"`
	Media           struct {
		Nodes []struct {
			Code    string `json:"code"` // url of the post
			Date    int64  `json:"date"`
			Caption string `json:"caption"`
		} `json:"nodes"`
		Count    int64 `json:"count"`
		PageInfo struct {
			HasNextPage bool   `json:"has_next_page"`
			EndCursor   string `json:"end_cursor"`
		} `json:"page_info"`
	} `json:"media"`

func GetUserInfoNoLogin

func GetUserInfoNoLogin(username string) (ui UserInfo, err error)

Given user name, return information of the user name without login.

user, err := GetUserInfoNoLogin("instagram")
if err != nil {


Discovering — and telling — stories from around the world. Curated by Instagram’s community team.

Jump to

Keyboard shortcuts

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