-
-
Save mamantoha/1129631 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'oauth2' | |
| require 'mechanize' | |
| @client = OAuth2::Client.new( | |
| 'client_id', | |
| 'client_secret', | |
| :site => 'https://api.vk.com/', | |
| :token_url => '/oauth/token', | |
| :authorize_url => '/oauth/authorize' | |
| ) | |
| auth_url = @client.auth_code.authorize_url( | |
| :redirect_uri => 'http://api.vk.com/blank.html', | |
| :scope => '', | |
| :display => 'wap' | |
| ) | |
| agent = Mechanize.new{|a| a.user_agent_alias = 'Linux Konqueror'} | |
| login_page = agent.get(auth_url) | |
| login_form = login_page.forms.first | |
| login_form.email = 'email' | |
| login_form.pass = 'pass' | |
| verify_page = login_form.submit | |
| if verify_page.uri.path == '/oauth/authorize' | |
| if /m=4/.match(verify_page.uri.query) | |
| raise "Вказано невірний логін або пароль." | |
| elsif /s=1/.match(verify_page.uri.query) | |
| grant_access_page = verify_page.forms.first.submit | |
| end | |
| else | |
| grant_access_page = verify_page | |
| end | |
| code = /code=(?<code>.*)/.match(grant_access_page.uri.fragment)['code'] | |
| @access_token = @client.auth_code.get_token(code) | |
| @access_token.options[:param_name] = 'access_token' | |
| @access_token.options[:mode] = :query | |
| @access_token.get('/method/getProfiles', :params => {:uids => '1', :fields => 'city,country'}).parsed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'oauth2' | |
| require 'mechanize' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @client = OAuth2::Client.new( | |
| 'client_id', | |
| 'client_secret', | |
| :site => 'https://api.vk.com/', | |
| :token_url => '/oauth/token', | |
| :authorize_url => '/oauth/authorize' | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| auth_url = @client.auth_code.authorize_url( | |
| :redirect_uri => 'http://api.vk.com/blank.html', | |
| :scope => '', | |
| :display => 'wap' | |
| ) | |
| agent = Mechanize.new{|a| a.user_agent_alias = 'Linux Konqueror'} | |
| login_page = agent.get(auth_url) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| login_form = login_page.forms.first | |
| login_form.email = 'email' | |
| login_form.pass = 'pass' | |
| verify_page = login_form.submit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if verify_page.uri.path == '/oauth/authorize' | |
| if /m=4/.match(verify_page.uri.query) | |
| raise "Вказано невірний логін або пароль." | |
| elsif /s=1/.match(verify_page.uri.query) | |
| grant_access_page = verify_page.forms.first.submit | |
| end | |
| else | |
| grant_access_page = verify_page | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| code = /code=(?<code>.*)/.match(grant_access_page.uri.fragment)['code'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @access_token = @client.auth_code.get_token(code) | |
| @access_token.options[:param_name] = 'access_token' | |
| @access_token.options[:mode] = :query |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @access_token.get('/method/getProfiles', :params => {:uids => '1', :fields => 'city,country'}).parsed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment