M
M
Mors Clamor2014-06-13 21:14:30
In contact with
Mors Clamor, 2014-06-13 21:14:30

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")

After each successful receipt of data (when access_token<>"" and when user_id<>""), a MessageBox appears with a message about the successful receipt of, for example, an access_token and the key itself.
b833572b0ad6485a99398afc82dcf9e8.png
Same story with user_id. Only about me issued only the first 3 digits. This is how i got the key and id
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

And here are the
fdd2c28ef77d461fa9234b6a657fd119.png
first 3 digits from the real one. Help me please.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
OvLab, 2014-06-14
@66demon666

>> 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

Second, we fix the function call by explicitly passing an empty string as strEnd:
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 question

Ask a Question

731 491 924 answers to any question