|
-
Feb 5th, 2025, 09:16 AM
#1
Thread Starter
Member
H2 API search in PLAINTEXT using VB6?
I'm using VB6 on Win11. My current project is about querying Discogs. I have registered the application with them, gotten the key & secret (strings). In my code I've come as far as checking if my (Discogs) token is missing and if it is, authenticate again.
I'm able to auhenticate, and have stored the token and secret (can be fetched with getOAuthToken(), getOAuthTokenSecret())
In the same session, just seconds later, I'm trying to search. Running the code below returns:
"401 - Unauthorized {"message": "You must authenticate to access this resource."}"
The code:
Code:
Private Sub cmdSearch_Click()
'getMyKey, getMySecret, getOAuthToken, getOAuthTokenSecret returns the strings for key, token and secrets
Dim sOAuthTimestamp As String: sOAuthTimestamp = Left(CStr(Timer * 86400), 8)
Dim sAuthorizationHeader As String, sSearchURL As String
Dim xmlHttp As Object ' ' Declare and...
Set xmlHttp = CreateObject("MSXML2.XMLHTTP") ' ...create the XMLHTTP object
sAuthorizationHeader = "OAuth " & _
"oauth_consumer_key=""" & getMyKey() & """, " & _
"oauth_nonce=""" & getNonce(8) & """, " & _
"oauth_signature=""" & UrlEncode2(getMySecret() & "&" & getOAuthTokenSecret()) & """, " & _
"oauth_signature_method=""PLAINTEXT"", " & _
"oauth_timestamp=""" & sOAuthTimestamp & """, " & _
"oauth_token=""" & getOAuthToken() & """, " & _
"oauth_version=""1.0"""
'ie: https://api.discogs.com/database/search?artist=ABBA
sSearchURL = getSearchURL(txtSearch(0).text, txtSearch(1).text, txtSearch(2).text), artist album title
xmlHttp.Open "GET", sSearchURL, False
xmlHttp.setRequestHeader "Authorization", sAuthorizationHeader
xmlHttp.setRequestHeader "User-Agent", App.Title & "/" & App.Major & "." & App.Minor & " (Windows; VB6)"
xmlHttp.send
If xmlHttp.Status = 200 Then
lblSearchResult.Caption = xmlHttp.responseText
Else
lblSearchResult.Caption = Now & ", error: " & xmlHttp.Status & " - " & xmlHttp.statusText & vbCrLf & xmlHttp.responseText
End If
Set xmlHttp = Nothing
End Sub
What am I doing wrong here?
Last edited by JohnPotier; Feb 6th, 2025 at 06:57 AM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|