Class: IgApi::Account
- Inherits:
-
Object
- Object
- IgApi::Account
- Defined in:
- lib/IgApi/account.rb
Class Method Summary collapse
Instance Method Summary collapse
- #api ⇒ Object
- #initialized ⇒ Object
- #login(username, password, config = IgApi::Configuration.new) ⇒ Object
- #search_for_user(user, username) ⇒ Object
Class Method Details
.search_for_user_graphql(user, username) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/IgApi/account.rb', line 52 def self.search_for_user_graphql(user, username) endpoint = "https://www.instagram.com/#{username}/?__a=1" result = IgApi::API.http( url: endpoint, method: 'GET', user: user ) response = JSON.parse result.body, symbolize_names: true return nil unless response[:user].any? { profile_id: response[:user][:id], external_url: response[:user][:external_url], followers: response[:user][:followed_by][:count], following: response[:user][:follows][:count], full_name: response[:user][:full_name], avatar_url: response[:user][:profile_pic_url], avatar_url_hd: response[:user][:profile_pic_url_hd], username: response[:user][:username], biography: response[:user][:biography], verified: response[:user][:is_verified], medias_count: response[:user][:media][:count], is_private: response[:user][:is_private] } end |
Instance Method Details
#api ⇒ Object
7 8 9 10 11 |
# File 'lib/IgApi/account.rb', line 7 def api @api = IgApi::Http.new if @api.nil? @api end |
#initialized ⇒ Object
3 4 5 |
# File 'lib/IgApi/account.rb', line 3 def initialized @api = nil end |
#login(username, password, config = IgApi::Configuration.new) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/IgApi/account.rb', line 13 def login(username, password, config = IgApi::Configuration.new) user = User.new username, password request = api.post( Constants::URL + 'accounts/login/', format( 'ig_sig_key_version=4&signed_body=%s', IgApi::Http.generate_signature( device_id: user.device_id, login_attempt_user: 0, password: user.password, username: user.username, _csrftoken: 'missing', _uuid: IgApi::Http.generate_uuid ) ) ).with(ua: user.useragent).exec json_body = JSON.parse request.body logged_in_user = json_body['logged_in_user'] user.data = { id: logged_in_user['pk'], full_name: logged_in_user['full_name'], is_private: logged_in_user['is_private'], profile_pic_url: logged_in_user['profile_pic_url'], profile_pic_id: logged_in_user['profile_pic_id'], is_verified: logged_in_user['is_verified'], is_business: logged_in_user['is_business'] } = [] = request.get_fields('set-cookie') .each do || .push(.split('; ')[0]) end = .join('; ') user.config = config user.session = user end |
#search_for_user(user, username) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/IgApi/account.rb', line 77 def search_for_user(user, username) rank_token = IgApi::Http.generate_rank_token user.session.scan(/ds_user_id=([\d]+);/)[0][0] endpoint = 'https://i.instagram.com/api/v1/users/search/' param = format('?is_typehead=true&q=%s&rank_token=%s', username, rank_token) result = api.get(endpoint + param) .with(session: user.session, ua: user.useragent).exec json_result = JSON.parse result.body if json_result['num_results'] > 0 user_result = json_result['users'][0] user_object = IgApi::User.new username, nil user_object.data = { id: user_result['pk'], full_name: user_result['full_name'], is_private: user_result['is_prive'], profile_pic_url: user_result['profile_pic_url'], profile_pic_id: user_result['profile_pic_id'], is_verified: user_result['is_verified'], is_business: user_result['is_business'] } user_object.session = user.session user_object end end |