0

Stuck please help

This is what I have so far
Dim ResponseKey As String
Dim i As Integer
i = DataGridView1.CurrentRow.Index
Dim User As String
Dim PWD As String
User = DataGridView1.Item(0, i).Value
PWD = DataGridView1.Item(1, i).Value

'Try and Log In
Debug.WriteLine("Getting Response Key")




ResponseKey = fetchURL("https://login.yahoo.com/WSLogin/V1/get_auth_token?&login=" & User & "&passwd=" & PWD & "&oauth_consumer_key=dj0yJmk9ZWo4dEYzV204OWlDJmQ9WVdrOVdWcEhUMnh4TldrbWNHbzlNa
kF4TURjeU16RTJNZy0tJnM9Y29uc3VtZXJzZWNyZXQmeD03MQ--", True, "")


Debug.Print(ResponseKey)
Dim KeyR() As String
KeyR = Split(ResponseKey, "=")
' Debug.Print(KeyR(1))

Dim random As New Random
Dim postdata As String
Dim Status As String = "I am now logged in"
'Time To Send User Information
Dim tUrl As String = "https://api.login.yahoo.com/oauth/v2/get_token" & _
"?&oauth_consumer_key=dj0yJmk9ZWo4dEYzV204OWlDJmQ9WVdrOVdWcEhUMnh4TldrbWNHbzlNa
kF4TURjeU16RTJNZy0tJnM9Y29uc3VtZXJzZWNyZXQmeD03MQ--" & _
"&oauth_signature_method=PLAINTEXT" & _
"&oauth_nonce=" & random.Next(10000000, 99999999) & _
"&oauth_timestamp=" & getTimestamp() & _
"&oauth_signature=1df17a91c4abccb5ee2c0a557b1d7f51bb29d8a9" & "%26" & _
"&oauth_version=1.0" & _
"&oauth_token=" & KeyR(1) & _
"&oauth_verifier=NONE"
Debug.Print(tUrl)
Dim rs As String = fetchURL(tUrl, True, "")
Debug.Print(rs)

Dim KAuth() As String
KAuth = Split(rs, "&")

Debug.Print(KAuth(0))
Debug.Print(KAuth(1))

Dim OAuthKeySec() As String
OAuthKeySec = Split(KAuth(1), "=")





Dim url As String = "http://developer.messenger.yahooapis.com/v1/session" & _
"?oauth_consumer_key=dj0yJmk9ZWo4dEYzV204OWlDJmQ9WVdrOVdWcEhUMnh4TldrbWNHbzlNakF4T
URjeU16RTJNZy0tJnM9Y29uc3VtZXJzZWNyZXQmeD03MQ--" & _
"&oauth_nonce=" & random.Next(10000000, 99999999) & _
"&oauth_signature=1df17a91c4abccb5ee2c0a557b1d7f51bb29d8a9" & "%26" & OAuthKeySec(1) & _
"&oauth_signature_method=PLAINTEXT" & _
"&oauth_timestamp=" & getTimestamp() & _
"&" & KAuth(0) & _
"&oauth_version=1.0" & _
"&notifyServerToken=1"
Debug.Print(url)
postdata = "{\""presenceState\"" : " & 0 & ", \""presenceMessage\"" : """ & Status & """}"

rs = fetchURL(url, True, "")
Debug.Print(rs)






End Sub
Public Function fetchURL(ByVal url As String, ByVal json As Boolean, ByVal postData As String) As String
_error = ""
Dim sb As New StringBuilder()
Dim buf As Byte() = New Byte(8191) {}
Try
Dim request As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest)
If json Then
request.ContentType = "application/json; charset=utf-8"
End If
If postData <> "" Then
request.Method = "POST"
Dim encoding__1 As New ASCIIEncoding()
Dim data As Byte() = encoding__1.GetBytes(postData)
request.ContentLength = data.Length
Dim newStream As Stream = request.GetRequestStream()
newStream.Write(data, 0, data.Length)
newStream.Close()
End If
Dim response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)
Dim resStream As Stream = response.GetResponseStream()
Dim tempString As String = Nothing
Dim count As Integer = 0
Do
count = resStream.Read(buf, 0, buf.Length)
If count <> 0 Then
tempString = Encoding.ASCII.GetString(buf, 0, count)
sb.Append(tempString)
Debug.WriteLine(tempString)
End If
Loop While count > 0
Catch e As WebException
_error = e.Message
MsgBox(_error)

Return ""
End Try
Return sb.ToString()
End Function

But after I try and submit the request to http://developer.messenger.yahooapis.com/v1/session i get an error 401 Not authorized. However, if I take the compiled url from the debug line at debug.print(url) and enter that in a browser. It returns a file calle dsession with a crumb id. Whats wrong with my code that it cant understand that?

by
2 Replies
  • When I open the session file that th ebrowser downlods in note pad this is what it says

    {"loggedIn":0,"crumb":"nA4Zi39zUmc"}


    So how to I get my code to get that file from the httpwebrequest and ge tthe crumb out of it
    0
  • QUOTE (Jeff Yeager @ Dec 7 2010, 12:36 PM) <{POST_SNAPBACK}>
    When I open the session file that th ebrowser downlods in note pad this is what it says

    {"loggedIn":0,"crumb":"nA4Zi39zUmc"}


    So how to I get my code to get that file from the httpwebrequest and ge tthe crumb out of it


    FetchURL uses POST method, browser uses GET method. It is different. Check this page out http://developer.yahoo.com/messenger/guide...ssionmanagement

    Please copy your HTTP response header here.
    0

Recent Posts

in Messenger IM SDK