Code Monkey home page Code Monkey logo

goinsta's Introduction

Golang + Instagram Private API

Unofficial Instagram API for Golang

Build Status GoDoc Go Report Card Gitter chat

Features

  • HTTP2 by default. Goinsta uses HTTP2 client enhancing performance.
  • Object independency. Can handle multiple instagram accounts.
  • Like Instagram mobile application. Goinsta is very similar to Instagram official application.
  • Simple. Goinsta is made by lazy programmers!
  • Backup methods. You can use Export and Import functions.
  • Security. Your password is only required to login. After login your password is deleted.
  • No External Dependencies. GoInsta will not use any Go packages outside of the standard library.

Package installation

go get -u -v gopkg.in/ahmdrz/goinsta.v2

Example

package main

import (
	"fmt"

	"gopkg.in/ahmdrz/goinsta.v2"
)

func main() {  
  insta := goinsta.New("USERNAME", "PASSWORD")

  // Export your configuration
  // after exporting you can use Import function instead of New function.
  // insta, err := goinsta.Import("~/.goinsta")
  // it's useful when you want use goinsta repeatedly.
  insta.Export("~/.goinsta")

  ...
}

Projects using goinsta

Legal

This code is in no way affiliated with, authorized, maintained, sponsored or endorsed by Instagram or any of its affiliates or subsidiaries. This is an independent and unofficial API. Use at your own risk.

Versioning

Goinsta used gopkg.in as versioning control. Stable new API is the version v2.0. You can get it using:

$ go get -u -v gopkg.in/ahmdrz/goinsta.v2

Or

If you have GO111MODULE=on

$ go get -u github.com/ahmdrz/goinsta/v2

Donate

Ahmdrz

btc Bitcoin: 1KjcfrBPJtM4MfBSGTqpC6RcoEW1KBh15X

Mester

btc Bitcoin: 37aogDJYBFkdSJTWG7TgcpgNweGHPCy1Ks

Analytics

goinsta's People

Contributors

ahmdrz avatar albina-art avatar alejoloaiza avatar bigjk avatar bupychuk avatar danijel-bjelancevic avatar dgrr avatar dmrlsn avatar ghostiam avatar glebtv avatar gspera avatar hadidimad avatar icholy avatar jaynagpaul avatar kayalardanmehmet avatar kemics avatar kfur avatar mattketmo avatar mosoriob avatar n33pm avatar nsa avatar obalunenko avatar rakd avatar robertgzr avatar seankhliao avatar sklinkert avatar sourcesoft avatar sviande avatar vitaliikapliuk avatar zhuharev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

goinsta's Issues

Does "follow" method really works?

I have just tried to write a sample script:

insta := goinsta.New("CORRECT_USER", "CORRECT_PASS")
if err := insta.Login(); err != nil {
	panic(err)
}

defer insta.Logout()
_, err := insta.Follow("CORRECT_ID")
if err != nil {
	fmt.Println(err)
}

And it doesn't work, but if I do it manually and then just call 'unfollow' with the same ID, it works (it unfollows)

Empty TrayUserResponse.Media in GetUserStories

func main() {
	id, _ := inst.GetUserByUsername("someusername")
       re, err := inst.GetUserStories(id.User.ID)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%#v", re.Media)
}

This return empty Media.

Get all posts - problem

Hello.

Im trying to get all posts from my instagram. I have 23 posts, but the goinsta returns the lastest 18. I dont know why. Can you help me?

Get the Feed:
feed, err := insta1.UserFeed(instaID,"","")

The posts array: (this array should have 23 posts, but have only the lastest 18)
feed.Items[]

Instagram analysed: https://www.instagram.com/enmob/

tks.

What is the maxid parameter and from where to get it

Hey guys , hope you have a great coding day
sorry if i bother anyone who is reading this but can someone explain where to get the maxid parameter
which i find almost in every freaking function that i need

when i call the UserFollowers(userid,maxid) i just don't know what to put for maxid so i put a random number and it always panics

many thanks in advance ##

`package main

import "github.com/ahmdrz/goinsta"
import "fmt"

func main() {
insta := goinsta.New("mylogin", "mypass")

if err := insta.Login(); err != nil {
	panic(err)
}

defer insta.Logout()
fmt.Print("phase01")
resp, err := insta.UserFollowers("someonesuserid", "don't know what to put here")
if err != nil {
	panic(err)
}
fmt.Print("phase02")
if resp.Status != "ok" {
	panic("Error occured , " + resp.Status)
}
fmt.Print("phase03")
for _, item := range resp.Users {
	if len(item.Username) > 30 {
		item.Username = item.Username[:30]
	}
	fmt.Println(item.Username)
}
fmt.Print("phase04")

}
`

Timeline() giving me old feed

I have created this user in Instagram and followed a few public celebrities normally from my phone. After Login() and then Timeline() from Go using your lib everything works just fine and I can fetch feed and paginate. But when I call run it again Timeline() keeps giving me the same feed again and again.

I realized after opening Instagram timeline on my phone and viewing new posts once, next time I run the Go program, Timeline func fetches all the new feeds successfully and I can paginate and everything works just fine.
It feels like opening instagram on phone triggers sth that let Timeline() fetch new items not the old cached ones.
Have you ever experienced this or is it supposed to happen?

Premium Features

Are You Willing To Extend This Library For A Monthly Subscription?

Similar To https://github.com/mgp25/Instagram-API/issues/1231

Different error values

Hello,

Sometimes some requests cause an error, then HTML code of the Instagram page is wrapped as an error. And it may be not useful because to understand the reason of actual error we need to check it f.e via Contains function.

Maybe we should have some errors as the global variables and return them?

why the instagram api doesn't return any response?

I'm using InstagramAPI to create a simple program that uploads a photo. When I run it, no response is returned and doesn't upload. I run it:
go run test.go
and it doesn't do anything. this my code:

package main

import (
    "fmt"

    "github.com/ahmdrz/goinsta"
)

func main() {
    insta := goinsta.New("my_username", "my_password")

    if err := insta.Login(); err != nil {
        panic(err)
    }

    defer insta.Logout()

    fmt.Println("Hello")

    resp, _ := insta.UploadPhoto("/home/muhammad/Pictures/Screenshot from 2017-05-02 20-38-29.jpg", "...", insta.NewUploadID(), 87,goinsta.Filter_Lark) // default quality is 87

    fmt.Println(resp.Status)
}

It prints Hello but API doesn't work. what is wrong with it? :|
@ahmdrz we are countrymen so scratch my back ;)

Error while calling DirectMessage two times

Hello, I'm facing error while using DirectMessage two times for same user, even with a sleep of 5 seconds in between, first message reaches the other user, but second message does NOT reach. It is important to mention that there is not error returned for neither of the calls, both return status ok, but the second message is lost (lost in the sense that is not visible in the instagram app). This is the code:

func main() {
	insta := goinsta.New("myuser", "mypwd")
	if err := insta.Login(); err != nil {
		panic(err)
	}
	defer insta.Logout()
	user, err := insta.GetUserByUsername("the user name of someone your follow")
	var Id int64
	Id = user.User.ID
	fmt.Println(Id)
	_, err = insta.DirectMessage(strconv.FormatInt(Id, 10), "Hello 1")
	if err != nil {
		fmt.Println(err)
	}
	time.Sleep(5 * time.Second)
	resp, err := insta.DirectMessage(strconv.FormatInt(Id, 10), "Hello 2")
	if err != nil {
		fmt.Println(err)
	}
	b, err := json.Marshal(resp)
	fmt.Println(string(b))
}

How to get photos from post with multiple files?

For example https://www.instagram.com/p/BYOzEg5Bgr7/

func GetAllPhotos(insta *goinsta.Instagram, username string) []string {
	//r, _ := regexp.Compile("(s|p)[0-9]{3}x[0-9]{3}")
	maxID := ""
	c, err := insta.GetUserByUsername(username)
	if err != nil {
		log.Fatal(err)
	}
	count, _ := insta.GetUserByID(c.User.ID)
	var all = []string{}
	i := 0
	for i < count.User.MediaCount {
		i += 18
		feed, _ := insta.UserFeed(c.User.ID, maxID, "")
		for _, item := range feed.Items {
			for _, photo := range item.ImageVersions2.Candidates {
				//if !r.MatchString(photo.URL) {
				p := strings.Split(photo.URL, "?")
				all = append(all, p[0])
				//}
			}
		}
		maxID = feed.NextMaxID
	}
	//RemoveDuplicates(&all)
	return all
}

Then I have all photos where photo just one in post, all post whith multiple file are ignore. What I do wrong?

Tagged in feed?

Is there a way to get the media that a user is tagged in (like the last tab on a user profile)?

Unexpected end of JSON input

I'm using follow-sync and was experiencing this error caused by this library: kirsle/follow-sync#2 (comment)

2017/03/06 10:33:46 Beginning the data collection process...
2017/03/06 10:33:46 Collecting your 'Followers' list
panic: unexpected end of JSON input

goroutine 1 [running]:
github.com/kirsle/follow-sync/src.(*App).getFollowers(0xc42004df18)
	/Users/craig/go/src/github.com/kirsle/follow-sync/src/insta.go:30 +0x251
github.com/kirsle/follow-sync/src.(*App).Run(0xc42004df18)
	/Users/craig/go/src/github.com/kirsle/follow-sync/src/app.go:45 +0xf3
main.main()
	/Users/craig/go/src/github.com/kirsle/follow-sync/main.go:23 +0x1aa

My account has over 10,000 followers and I was experiencing this error earlier. It does not happen every time but it happens fairly regularly when running.

Issue with DirectMessage

Hello guys, first to thank you for this great effort to make Go great.

I'm testing this API and getting success in most of the methods, however the DirectMessage is not working for me, im getting error "Oops, an error occurred." and empty struct. Can anyone help?

func InstaDirectMessage() {
resp, err := Insta.DirectMessage("some_girl", "Hello")
if err != nil {
fmt.Println(err)
}
fmt.Println(resp)
}

StoryLocations values mapped as float

Some of the fields in the stories are mapped as float...

For example:

StoryLocations: ([]interface {}) (len=1 cap=4) {
  (map[string]interface {}) (len=8) {
   (string) (len=1) "y": (float64) 0.8045723532635211,
   (string) (len=1) "z": (float64) 0,
   (string) (len=5) "width": (float64) 0.6034209785511461,
   (string) (len=6) "height": (float64) 0.07064598804581801,
   (string) (len=8) "rotation": (float64) 6.148272024050988e-07,
   (string) (len=9) "is_pinned": (float64) 0,
   (string) (len=8) "location": (map[string]interface {}) (len=9) {
    (string) (len=15) "external_source": (string) (len=15) "facebook_places",
    (string) (len=4) "name": (string) (len=50) "Hong Kong International Airport 香港國際機場",
    (string) (len=7) "address": (string) "",
    (string) (len=4) "city": (string) "",
    (string) (len=10) "short_name": (string) (len=50) "Hong Kong International Airport 香港國際機場",
    (string) (len=3) "lng": (float64) 113.93393405317,
    (string) (len=3) "lat": (float64) 22.312970496414,
    (string) (len=2) "pk": (float64) 1.502180729855002e+15,
    (string) (len=18) "facebook_places_id": (float64) 1.502180729855002e+15
   },
   (string) (len=1) "x": (float64) 0.532231531524052
  }
 },

Goinsta Appengine GCP

I'm trying to use goinsta in gcp appengine. an error ocurres when call Login().
Error:
login failed for enmob error Get https://i.instagram.com/api/v1/si/fetch_headers/?challenge_type=signup&guid=54fbe7af-afb9-42e8-80ab-18137e733bff: http.DefaultTransport and http.DefaultClient are not available in App Engine. See https://cloud.google.com/appengine/docs/go/urlfetch/

Code:
func main() {
http.HandleFunc("/", buscaInstagram)
appengine.Main()
}

func buscaInstagram(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
http.NotFound(w, r)
return
}
ctx := appengine.NewContext(r)
projectID := os.Getenv("GCLOUD_DATASET_ID")

var errdts error
datastoreClient, errdts = datastore.NewClient(ctx, IDprojeto)
if errdts != nil {
	fmt.Print(errdts)
}

var erroMsg string
insta := goinsta.New("name", "*****")

if err := insta.Login(); err != nil {
	fmt.Print(err)
	erroMsg = err.Error()
}

...

Someone can help me?
tks.

Method for Main feed

Hello all, one question, What is the method for the main feed, (home Icon) of instagram? Not the stories, I mean the latest posts by the people Im following. Thanks!!!

Func UserFollowing does not take argument maxID

Hello! I want to get all user followings. This my code:

insta := goinsta.NewViaProxy(login, passw, "https://user:[email protected]:11223")
if err := insta.Login(); err != nil {
	fmt.Println("insta.Login error:", err)
}
defer insta.Logout()

tempMaxID := ""
allUsers := response.UsersResponse{}

for {
	q, err := insta.UserFollowing(1987641926, tempMaxID)
	if err != nil {
		break
	}
	allUsers.Users = append(allUsers.Users, q.Users...)
	if q.NextMaxID == "" {
		break
	}
	tempMaxID = q.NextMaxID
}

arr := []string{}
for _, user := range allUsers.Users {
	arr = append(arr, user.Username)
}

fmt.Println(arr)

But it does not work. The function does not take the maxID value and the loop never stops.

v2 - panic: runtime error: invalid memory address or nil pointer dereference

Profiles, Search, Timeline, Activity, Inbox => nil on New() / Login()

ig := goinsta.New(name, pass)
if err := ig.Login(); err != nil {
	logrus.WithError(err).Error("instagram login")
}

logrus.Info(ig.Profiles)
logrus.Info(ig.Account)
logrus.Info(ig.Search)
logrus.Info(ig.Timeline)
logrus.Info(ig.Activity)
logrus.Info(ig.Inbox)

// time="2018-05-17T20:37:25+02:00" level=info msg="<nil>" 
// time="2018-05-17T20:37:25+02:00" level=info msg="&{...}" 
// time="2018-05-17T20:37:25+02:00" level=info msg="<nil>" 
// time="2018-05-17T20:37:25+02:00" level=info msg="<nil>" 
// time="2018-05-17T20:37:25+02:00" level=info msg="<nil>" 
// time="2018-05-17T20:37:25+02:00" level=info msg="<nil>" 

because init() get called only on Import()

Image size

Hi! I'm trying parse feed list and have some trouble.

feed, _ := insta.UserFeed(c.User.ID, "", "")
	for _, photos := range feed.Items {
		for _, photo := range photos.ImageVersions2.Candidates {
			println(photo.URL)
		}
	}

And in the response have photos at 240x240.
How I can request original or biggest size? Thanks for answer.

How to use Import and Export functions ?

hello, I am a beginner in Golang programming, I don't understand how to use exactly the Import and Export functions. Can you say me how ? (may I keep the bytes in a file?)
Thanks

Get about user

In the official app can view phone number, email, etc.

nhn3cjsmjls

I did not find a method for obtaining this information. does the library provide such an opportunity?

what is the best practice to receive realtime direct messages?

I seems that insta.GetV2Inbox() returns all direct messages. What I want is to receive realtime direct messages.

At first glance, I thinks I need a for loop on insta.GetV2Inbox(), but unfortunately, I did not figure it out.

what is the best practice to receive realtime direct messages?

[v2] posts per tag

Looking at the API, the schema and the examples I am a little puzzled on how to get the posts for a certain tag.

Do you accept my changes if they break compatibility?

@ahmdrz I'm now working on redoing your code so it's easier to use. I hide all the unnecessary Pk conversions inside the code so that the user does not have to think about it. Also, it was necessary to delete duplicate data in the structuries.

I have a question about the scale of the changes, what if my changes break down user programs?

lastJson as a local package variable

Hello, thank you for your nice package.

I have noticed, that you are using in insta.sendRequest() method the local variable lastJson, and checking its value in all the methods, that are using the insta.sendRequest() method. I think, that it is not concurrent safe, and a little bit not explicit.

In my opinion, lastJson should be a private field of insta struct. What do you think about it?

Git Tags

Hey! I am creating a new project and would love to use this lib. I am using dep to maintain my dependencies and would love if goinsta followed the versioning format, which is semver through git tags. Thank you for making a great lib!

Unable to login?

panic: runtime error: slice bounds out of range

goroutine 1 [running]:
panic(0x3b1800, 0xc82000a0c0)
	/usr/local/go/src/runtime/panic.go:481 +0x3e6
github.com/ahmdrz/goinsta.(*Instagram).Login(0xc8200c2000, 0x0, 0x0)
	/go/src/github.com/ahmdrz/goinsta/goinsta.go:137 +0xef4

The code in the backtrace is :

	data := insta.cookie[strings.Index(insta.cookie, "csrftoken=")+10:]
	data = data[:strings.Index(data, ";")]

So presumably something malformed in the returned cookie? /shrug

Doen't return all followers

With a list of followers 230 long, it is not returning all of the followers when you get the followers.

r, err := insta.SelfUserFollowers("")

Is this connected to the undocumented BigList variable?

instagram question

Hi,

does Instagram still provide Realtime subscriptions for tags, locations and geographies?

Thanks,
Gerald

getImageDimension leaks file descriptor.

getImageDimension doesn't close the file.

goinsta/goinsta.go

Lines 984 to 995 in 2f5d010

func getImageDimension(imagePath string) (int, int, error) {
file, err := os.Open(imagePath)
if err != nil {
return 0, 0, err
}
image, _, err := image.DecodeConfig(file)
if err != nil {
return 0, 0, err
}
return image.Width, image.Height, nil
}

The account is logged out when get followers

I want to get followers from a certain user so I did:

package main

import (
        "fmt"

        "github.com/ahmdrz/goinsta"
)

func main() {
        insta := goinsta.New("username", "password")

        if err := insta.Login(); err != nil {
                fmt.Println(err)
                return
        }

        fmt.Println("logged-in")
        defer insta.Logout()

        userResponse, err := insta.GetUserByUsername("unconventionalbaker")
        if err != nil {
                fmt.Println(err)
                return
        }
        fmt.Println("I took the ID")
        userID := userResponse.User.ID
        followersResponse, err := insta.TotalUserFollowers(userID)
        if err != nil {
                fmt.Println(err)
                return
        }

        fmt.Println("I got followers")

        for _, f := range followersResponse.Users {
                fmt.Println(f.Username)
        }
}

This print

logged-in
I took the ID
The account is logged out

After I took the ID I have to wait 1 minute and after that: The account is logged out, I thought due the large amount of followers of that user so now the question: How can I get the list of that account's followers?

Thanks

Help !

Hi dear contributors.

Did you see my last commit ?

Now we can import and export user info , So we do not have login after exit programs if we save exported data.

It's protected by AES algorithm.

@icholy @glebtv @sourcesoft @rakd @aaronarduino @GhostRussia

What is your Idea ?

I'm waiting for Travis tests.

400 Bad Request Media not found or unavailable (album image)

Hi! I try to get info about image

insta.MediaInfo(mediaId) for this image

https://www.instagram.com/p/BR_repxhx4O
id: 1477090425239445006

This is an image inside album.
Other non-album image is fine.

&{POST https://i.instagram.com/api/v1/media/1477090425239445006/info/ HTTP/1.1 1 1 map[Connection:[close] Accept:[*/*] Content-Type:[application/json; charset=UTF-8] Cookie2:[Version=1] Accept-Language:[en-US] User-Agent:[Instagram 10.1.0 Android (18/4.3; 320dpi; 720x1280; Xiaomi; HM 1SW; armani; qcom; en_US)]] 

{ig_sig_key_version=4&signed_body=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.%7B%22_csrftoken%22%3A%xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%22%2C%22_uid%22%3A%xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%22%2C%22_uuid%22%3A%xxxxxxxxxxxxxxxxxxxxxxxxxxxx%22%2C%22media_id%22%3A%221477090425239445006%22%7D} 0x122f800 293 [] false i.instagram.com map[] map[] <nil> map[]   <nil> <nil> <nil> <nil>}

400 Bad Request
panic: Invalid status code {"status": "fail", "message": "Media not found or unavailable"}

I also try original library mgp25/Instagram-API
It is working...

POST:  media/1477090425239445006/info/
DATA: ig_sig_key_version=4&signed_body=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.{"_uuid":"xxxxxx-xxxxxx-xxxxx-xxxxx-xxxxxxxxxxxxxx","_uid":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","_csrftoken":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","media_id":"1477090425239445006"}
← 200 	 1.45kB

I tried debugging it to understand this problem... but a little hard for me...

API Key login

Is there a way to login with API keys instead of username/password?

DirectMessage

Hello, thanks for your package, Im trying to send simple message through DirectMessage(), help me, please
screenshot from 2017-03-23 19-06-36

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.