Forum Discussion

calebv's avatar
calebv
Channel Surfer
4 years ago
Solved

Static Analysis Failing Due to Lack of getUserData

My app is failing the Static Analysis test with the following error: All authenticated channels must use the Request for Information (getUserData) API call to obtain a user's email address during th...
  • calebv's avatar
    4 years ago

    Finally figured it out. I was going off the incorrect examples shown in the third link I posted above, which has you create a Store object like:

    store = CreateObject("roChannelStore")

    And then call methods on that Store object like this:

    userData = store.GetUserData()

    However this is incorrect!

    Fortunately I ran across this blog post which alludes to the fact that the way I was trying it is the old way of doing it (as of 2016, yet Roku still shows it in the docs but won't allow it to pass Static Analysis!)

    https://blog.roku.com/developer/channelstore-node-billing-guide

    The correct way to implement "getUserData" is to create a Store node like this:

    store = CreateObject("roSGNode", "ChannelStore")

    Then you can set which pieces of data you want to get, and then set the command field to the method name you want to call as a String:

    store.command = "getUserData"

    Then listen to (observe) the userData field and set a callback to be run once the data is retrieved.

    Here's an example of the full flow showing how to get only the email from the user for use in a login screen:

    sub Init()
        m.store = CreateObject("roSGNode", "ChannelStore")
        info = CreateObject("roSGNode", "ContentNode")
        info.addFields({context: "signin"})
        m.store.requestedUserDataInfo = info
        m.store.requestedUserData = "email"
        m.store.command = "getUserData"
        m.store.observefield("userData", "OnEmail")
    end sub
    
    sub OnEmail()
        if m.store.userData <> invalid
            email = m.store.userData.email
    ' Do something with the email here end if end sub

    This finally passed the Static Analysis. Hopefully this helps some poor soul Googling down the road.