Skip to content
This repository has been archived by the owner on Aug 25, 2023. It is now read-only.

Fix some problems #347

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*~
*.o
*.a
*.so
Expand Down
44 changes: 40 additions & 4 deletions goinsta.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package goinsta
import (
"crypto/tls"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
Expand Down Expand Up @@ -448,9 +449,44 @@ func (inst *Instagram) Login() error {

// Logout closes current session
func (inst *Instagram) Logout() error {
_, err := inst.sendSimpleRequest(urlLogout)
inst.c.Jar = nil
inst.c = nil
result, err := json.Marshal(
map[string]interface{}{
"guid": inst.uuid,
"login_attempt_count": 0,
"_csrftoken": inst.token,
"device_id": inst.dID,
"adid": inst.adid,
"phone_id": inst.pid,
"username": inst.user,
"password": inst.pass,
"google_tokens": "[]",
},
)
if err != nil {
return err
}
body, err := inst.sendRequest(
&reqOptions{
Endpoint: urlLogout,
Query: generateSignature(b2s(result)),
IsPost: true,
Login: true,
},
)
if err != nil {
return err
}

// getting logout status
res := accountResp{}
err = json.Unmarshal(body, &res)
if err != nil {
return err
}
if res.Status != "ok" {
return fmt.Errorf("Logout failed, try later!")
}
inst = nil
return err
}

Expand Down Expand Up @@ -484,7 +520,7 @@ func (inst *Instagram) megaphoneLog() error {
"action": "seen",
"reason": "",
"device_id": inst.dID,
"uuid": generateMD5Hash(string(time.Now().Unix())),
"uuid": generateMD5Hash(fmt.Sprint(time.Now().Unix())),
},
)
if err != nil {
Expand Down
30 changes: 8 additions & 22 deletions shortid.go
Original file line number Diff line number Diff line change
@@ -1,31 +1,17 @@
package goinsta

import (
"fmt"
"strconv"
"strings"
)

func leftPad2Len(s string, padStr string, overallLen int) string {
var padCountInt int
padCountInt = 1 + ((overallLen - len(padStr)) / len(padStr))
var retStr = strings.Repeat(padStr, padCountInt) + s
return retStr[(len(retStr) - overallLen):]
}

const base64UrlCharmap = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"

func MediaIDFromShortID(code string) (string, error) {
strID := ""
for i := 0; i < len(code); i++ {
base64 := strings.Index(base64UrlCharmap, string(code[i]))
str2bin := strconv.FormatInt(int64(base64), 2)
sixbits := leftPad2Len(str2bin, "0", 6)
strID = strID + sixbits
func MediaIDFromShortID(code string) string {
alphabet := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
media_id := 0
for _, letter := range code {
media_id = (media_id * 64) + strings.Index(alphabet, string(letter))
}
result, err := strconv.ParseInt(strID, 2, 64)
if err != nil {
return "", err
}
return fmt.Sprintf("%d", result), nil
result := strconv.Itoa(media_id)

return result
}
6 changes: 1 addition & 5 deletions shortid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import (
)

func TestMediaIDFromShortID(t *testing.T) {
mediaID, err := MediaIDFromShortID("BR_repxhx4O")
if err != nil {
t.Fatal(err)
return
}
mediaID := MediaIDFromShortID("BR_repxhx4O")
if mediaID != "1477090425239445006" {
t.Fatal("Invalid mediaID")
}
Expand Down