Android Question Amazon Music / Login With Amazon

StephanP82

Member
Licensed User
Longtime User
Hi everyone,

i'm trying to get access to amazon music using its API. To use it, I've created an API Key in Amazon Developer concole. Following the API instructions I have to use Login For Amazon to authenticate my user name and password and i must pass the API Key.

My questions:
1. How can I add the API Key to my project descriped here in B4A? Where is the assets folder located?
2. How can I use OkHttpUtils2 to login and get the SecurityToken which is needed to get access to Amazon Music?

Thanks in advance.

Here is my code so far (the functions to get the SecurityToken and the login are currently empty):

B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private SecurityToken As String
   
    Private WV_Error As WebView
    Private PNL_Main As Panel
    Private PNL_Footer As Panel
    Private PNL_Header As Panel
End Sub

Public Sub Initialize
    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
   
    If SecurityToken.Length = 0 Then
        Wait For(GetSecurityToken) Complete (Result As Boolean)
        Wait For(Login(SecurityToken)) Complete (Result As Boolean)
    Else
        Wait For(Login(SecurityToken)) Complete (Result As Boolean)
        If Result = True Then
            Root.LoadLayout("MainPage")
            Private Job As HttpJob
            Job.Initialize("", Me)
            Job.GetRequest.SetContentType("application/json")  
            Job.Download("https://music-api.amazon.com/search/?keywords=hello")
            Wait For (Job) JobDone(Job As HttpJob)
        Else
            ToastMessageShow("Fehler beim Login", True)
        End If
    End If
End Sub

Private Sub JobDone(Job As HttpJob)
    Dim Response As String
    If Job.Success Then
        Response = Job.GetString
    Else
        Response = Job.ErrorMessage
    End If

    Job.Release
   
    If WV_Error.IsInitialized Then
        WV_Error.RemoveView
    Else
        WV_Error.Initialize("")
        Root.AddView(WV_Error, 0, 0, Root.Width, Root.Height)
    End If
   
    WV_Error.LoadHtml(Response)
End Sub

Private Sub GetSecurityToken As ResumableSub
   
End Sub

Private Sub Login(SecToken As String) As ResumableSub
   
End Sub
 

StephanP82

Member
Licensed User
Longtime User
Okay, thank you Erel. That means, I cannot use it in B4A?

I've seen that the OAuth 2.0 Protocoll is used to login. You posted an example for it here, but if I understand it correctly, I have to use the amazon library instead?

What will be needed to realize it in B4A?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Everything is accessible from B4A but if there is a specific library that is needed then you will also need it in your B4A project. Accessing requires some Java knowledge.

If they provide a standard OAuth 2 protocol then you don't need a library. You do need to learn the exact details required. I didn't see them on that page. I can help you with a specific question. Not with the full implementation of their protocol.
 
Upvote 0

StephanP82

Member
Licensed User
Longtime User
I've canceled the project, because we don't need it anymore and the effort don't equals the usebility. Anyway, thanks for the help.
 
Upvote 0
Top