#include <GUIConstants.au3>
#include <IE.au3>
Global $iAppID, $access_token
$iAppID = 4923780
$access_token = _VKAuth($iAppID, "offline,photos")
If Not @error Then
MsgBox(0, "Auth OK! Access_token", $access_token, 30)
Else
MsgBox(16, "Auth Error", "error#" & @error, 30)
EndIf
;========================================;
Func _VKAuth($aid, $scope = "offline")
Local $gui, $oIE, $sAuthURL, $url, $flag, $token
$sAuthURL = "https://oauth.vk.com/authorize?client_id=" & $aid & "&scope=" & $scope & "&redirect_uri=https://oauth.vk.com/blank.html&display=mobile&v=5.33&response_type=token"
$oIE = _IECreateEmbedded()
If Not IsObj($oIE) Then Return SetError(1, 0, 0)
$gui = GUICreate("VK API авторизация", 640, 580, (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, $WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)
GUICtrlCreateObj($oIE, 10, 40, 600, 360)
GUISetState(@SW_SHOW)
_IENavigate($oIE, $sAuthURL)
If @error Then
GUIDelete($gui)
Return SetError(2, 0, 0)
EndIf
$flag = 0
While 1
$url = _IEPropertyGet($oIE, "locationurl")
If StringInStr($url, '/blank.html#') Then
ConsoleWrite("URL: " & $url & @CRLF)
$token = StringRegExpReplace($url, '.*?access_token=([^&]+).*', '$1')
If @extended = 0 Then $token = ""
$expires = StringRegExpReplace($url, '.*?expires_in=([\d]+).*', '$1')
If @extended = 0 Then $expires = 0
$uid = StringRegExpReplace($url, '.*?user_id=([\d]+).*', '$1')
If @extended = 0 Then $uid = 0
If $token <> "" Then $flag = 1
ConsoleWrite(StringFormat("Info: token: %s; expires: %s; user ID: %s\r\n", $token, $expires, $uid))
ExitLoop
EndIf
If GUIGetMsg() = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
GUIDelete($gui)
If $flag = 1 Then
Return $token
Else
Return SetError(3, 0, 0)
EndIf
EndFunc ;==>_VKAuth