Answer the question
In order to leave comments, you need to log in
API VKontakte. Doesn't get user_id to the end. What to do?
I'm trying to work with the VKontakte API through VB.NET. I receive data: access_token and user_id. Here in this way
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
WebBrowser1.Navigate("http://api.vkontakte.ru/oauth/authorize?client_id=" & appID & "&scope=wall" & "&display=popup&response_type=token")
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
If e.Url.ToString().IndexOf("access_token") <> -1 Then
access_token = GetBetween(e.Url.ToString(), "access_token=", "&expires", 0)
End If
If access_token <> "" Then
MsgBox("Ключ доступа успешно получен. " & access_token)
End If
MsgBox(getProfiles("adam_moran").InnerXml)
If e.Url.ToString().IndexOf("user_id") <> -1 Then
user_id = GetBetween(e.Url.ToString(), "user_id=", 0)
End If
If user_id <> "" Then
MsgBox("id получен. " & user_id)
End If
End Sub
Answer the question
In order to leave comments, you need to log in
>> In the original string user_id completely?
>>In this case, there is an error in the parameters of the GetBetween function.
First, we fix the function so that it correctly processes the last token in the string - we add an additional condition in case strEnd is empty:
Public Function GetBetween(ByRef strSource As String, ByRef strStart As String, ByRef strEnd As String, Optional ByRef startPos As Integer = 0) As String
Dim iPos As Integer, iEnd As Integer, lenStart As Integer = strStart.Length
Dim strResult As String
strResult = String.Empty
iPos = strSource.IndexOf(strStart, startPos)
iEnd = strSource.IndexOf(strEnd, iPos + lenStart)
If iPos -1 AndAlso iEnd <> -1 Then
If strEnd.Length>0 Then
strResult = strSource.Substring(iPos + lenStart, iEnd - (iPos + lenStart))
Else
strResult = strSource.Substring(iPos + lenStart, strSource.Length-(iPos + lenStart))
End If
End If
Return strResult
End Function
If e.Url.ToString().IndexOf("user_id") <> -1 Then
user_id = GetBetween(e.Url.ToString(), "user_id=","", 0)
End If
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question