ig_api 0.0.15 → 0.0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +3 -3
- data/.rubocop.yml +3 -3
- data/.travis.yml +5 -5
- data/CODE_OF_CONDUCT.md +74 -74
- data/Gemfile +5 -5
- data/Gemfile.lock +38 -38
- data/LICENSE.txt +21 -21
- data/README.md +56 -56
- data/Rakefile +6 -6
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/ig_api.gemspec +38 -38
- data/lib/ig_api/account.rb +118 -115
- data/lib/ig_api/configuration.rb +4 -4
- data/lib/ig_api/constants.rb +22 -22
- data/lib/ig_api/device.rb +11851 -11851
- data/lib/ig_api/feed.rb +65 -77
- data/lib/ig_api/http.rb +119 -120
- data/lib/ig_api/thread.rb +56 -3
- data/lib/ig_api/user.rb +128 -120
- data/lib/ig_api/version.rb +3 -3
- data/lib/ig_api.rb +11 -11
- metadata +2 -2
data/lib/ig_api/account.rb
CHANGED
@@ -1,115 +1,118 @@
|
|
1
|
-
module IgApi
|
2
|
-
class Account
|
3
|
-
def initialized
|
4
|
-
@api = nil
|
5
|
-
end
|
6
|
-
|
7
|
-
def api
|
8
|
-
@api = IgApi::Http.new if @api.nil?
|
9
|
-
|
10
|
-
@api
|
11
|
-
end
|
12
|
-
|
13
|
-
def using(session)
|
14
|
-
user = User.new session: session
|
15
|
-
|
16
|
-
# response = api.get(Constants::URL + 'accounts/current_user/?edit=true')
|
17
|
-
# .with(ua: user.useragent, session: user.session).exec
|
18
|
-
#
|
19
|
-
# response.body
|
20
|
-
#
|
21
|
-
|
22
|
-
user
|
23
|
-
end
|
24
|
-
|
25
|
-
def login(username, password, config = IgApi::Configuration.new)
|
26
|
-
user = User.new username: username,
|
27
|
-
password: password
|
28
|
-
|
29
|
-
request = api.post(
|
30
|
-
Constants::URL + 'accounts/login/',
|
31
|
-
format(
|
32
|
-
'ig_sig_key_version=4&signed_body=%s',
|
33
|
-
IgApi::Http.generate_signature(
|
34
|
-
device_id: user.device_id,
|
35
|
-
login_attempt_user: 0, password: user.password, username: user.username,
|
36
|
-
_csrftoken: 'missing', _uuid: IgApi::Http.generate_uuid
|
37
|
-
)
|
38
|
-
)
|
39
|
-
).with(ua: user.useragent).exec
|
40
|
-
|
41
|
-
json_body = JSON.parse request.body
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
user
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
end
|
1
|
+
module IgApi
|
2
|
+
class Account
|
3
|
+
def initialized
|
4
|
+
@api = nil
|
5
|
+
end
|
6
|
+
|
7
|
+
def api
|
8
|
+
@api = IgApi::Http.new if @api.nil?
|
9
|
+
|
10
|
+
@api
|
11
|
+
end
|
12
|
+
|
13
|
+
def using(session)
|
14
|
+
user = User.new session: session
|
15
|
+
|
16
|
+
# response = api.get(Constants::URL + 'accounts/current_user/?edit=true')
|
17
|
+
# .with(ua: user.useragent, session: user.session).exec
|
18
|
+
#
|
19
|
+
# response.body
|
20
|
+
#
|
21
|
+
|
22
|
+
user
|
23
|
+
end
|
24
|
+
|
25
|
+
def login(username, password, config = IgApi::Configuration.new)
|
26
|
+
user = User.new username: username,
|
27
|
+
password: password
|
28
|
+
|
29
|
+
request = api.post(
|
30
|
+
Constants::URL + 'accounts/login/',
|
31
|
+
format(
|
32
|
+
'ig_sig_key_version=4&signed_body=%s',
|
33
|
+
IgApi::Http.generate_signature(
|
34
|
+
device_id: user.device_id,
|
35
|
+
login_attempt_user: 0, password: user.password, username: user.username,
|
36
|
+
_csrftoken: 'missing', _uuid: IgApi::Http.generate_uuid
|
37
|
+
)
|
38
|
+
)
|
39
|
+
).with(ua: user.useragent).exec
|
40
|
+
|
41
|
+
json_body = JSON.parse request.body
|
42
|
+
|
43
|
+
raise json_body['message'] if json_body['status'] == 'fail'
|
44
|
+
|
45
|
+
logged_in_user = json_body['logged_in_user']
|
46
|
+
|
47
|
+
user.data = {
|
48
|
+
id: logged_in_user['pk'],
|
49
|
+
full_name: logged_in_user['full_name'],
|
50
|
+
is_private: logged_in_user['is_private'],
|
51
|
+
profile_pic_url: logged_in_user['profile_pic_url'],
|
52
|
+
profile_pic_id: logged_in_user['profile_pic_id'],
|
53
|
+
is_verified: logged_in_user['is_verified'],
|
54
|
+
is_business: logged_in_user['is_business']
|
55
|
+
}
|
56
|
+
cookies_array = []
|
57
|
+
all_cookies = request.get_fields('set-cookie')
|
58
|
+
all_cookies.each do |cookie|
|
59
|
+
cookies_array.push(cookie.split('; ')[0])
|
60
|
+
end
|
61
|
+
cookies = cookies_array.join('; ')
|
62
|
+
user.config = config
|
63
|
+
user.session = cookies
|
64
|
+
|
65
|
+
user
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.search_for_user_graphql(user, username)
|
69
|
+
endpoint = "https://www.instagram.com/#{username}/?__a=1"
|
70
|
+
result = IgApi::API.http(
|
71
|
+
url: endpoint,
|
72
|
+
method: 'GET',
|
73
|
+
user: user
|
74
|
+
)
|
75
|
+
response = JSON.parse result.body, symbolize_names: true
|
76
|
+
return nil unless response[:user].any?
|
77
|
+
{
|
78
|
+
profile_id: response[:user][:id],
|
79
|
+
external_url: response[:user][:external_url],
|
80
|
+
followers: response[:user][:followed_by][:count],
|
81
|
+
following: response[:user][:follows][:count],
|
82
|
+
full_name: response[:user][:full_name],
|
83
|
+
avatar_url: response[:user][:profile_pic_url],
|
84
|
+
avatar_url_hd: response[:user][:profile_pic_url_hd],
|
85
|
+
username: response[:user][:username],
|
86
|
+
biography: response[:user][:biography],
|
87
|
+
verified: response[:user][:is_verified],
|
88
|
+
medias_count: response[:user][:media][:count],
|
89
|
+
is_private: response[:user][:is_private]
|
90
|
+
}
|
91
|
+
end
|
92
|
+
|
93
|
+
def search_for_user(user, username)
|
94
|
+
rank_token = IgApi::Http.generate_rank_token user.session.scan(/ds_user_id=([\d]+);/)[0][0]
|
95
|
+
endpoint = 'https://i.instagram.com/api/v1/users/search/'
|
96
|
+
param = format('?is_typehead=true&q=%s&rank_token=%s', username, rank_token)
|
97
|
+
result = api.get(endpoint + param)
|
98
|
+
.with(session: user.session, ua: user.useragent).exec
|
99
|
+
|
100
|
+
json_result = JSON.parse result.body
|
101
|
+
if json_result['num_results'] > 0
|
102
|
+
user_result = json_result['users'][0]
|
103
|
+
user_object = IgApi::User.new username: username
|
104
|
+
user_object.data = {
|
105
|
+
id: user_result['pk'],
|
106
|
+
full_name: user_result['full_name'],
|
107
|
+
is_private: user_result['is_prive'],
|
108
|
+
profile_pic_url: user_result['profile_pic_url'],
|
109
|
+
profile_pic_id: user_result['profile_pic_id'],
|
110
|
+
is_verified: user_result['is_verified'],
|
111
|
+
is_business: user_result['is_business']
|
112
|
+
}
|
113
|
+
user_object.session = user.session
|
114
|
+
user_object
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
data/lib/ig_api/configuration.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
module IgApi
|
2
|
-
class Configuration
|
3
|
-
attr_accessor :proxy_list
|
4
|
-
end
|
1
|
+
module IgApi
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :proxy_list
|
4
|
+
end
|
5
5
|
end
|
data/lib/ig_api/constants.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module IgApi
|
4
|
-
module Constants
|
5
|
-
PRIVATE_KEY = {
|
6
|
-
SIG_KEY: '
|
7
|
-
SIG_VERSION: '4',
|
8
|
-
APP_VERSION: '
|
9
|
-
}.freeze
|
10
|
-
|
11
|
-
HEADER = {
|
12
|
-
capabilities: '
|
13
|
-
type: 'WIFI',
|
14
|
-
host: 'i.instagram.com',
|
15
|
-
connection: 'Close',
|
16
|
-
encoding: 'gzip, deflate, sdch',
|
17
|
-
accept: '*/*'
|
18
|
-
}.freeze
|
19
|
-
|
20
|
-
URL = 'https://i.instagram.com/api/v1/'
|
21
|
-
end
|
22
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module IgApi
|
4
|
+
module Constants
|
5
|
+
PRIVATE_KEY = {
|
6
|
+
SIG_KEY: '673581b0ddb792bf47da5f9ca816b613d7996f342723aa06993a3f0552311c7d',
|
7
|
+
SIG_VERSION: '4',
|
8
|
+
APP_VERSION: '42.0.0.19.95'
|
9
|
+
}.freeze
|
10
|
+
|
11
|
+
HEADER = {
|
12
|
+
capabilities: '3brTPw==',
|
13
|
+
type: 'WIFI',
|
14
|
+
host: 'i.instagram.com',
|
15
|
+
connection: 'Close',
|
16
|
+
encoding: 'gzip, deflate, sdch',
|
17
|
+
accept: '*/*'
|
18
|
+
}.freeze
|
19
|
+
|
20
|
+
URL = 'https://i.instagram.com/api/v1/'
|
21
|
+
end
|
22
|
+
end
|