1

目前我正在为 Lightroom 制作一个插件,基本上必须登录用户并帮助他将图片上传到网站。不幸的是,我陷入了以下问题:

  • LrHttp 似乎不起作用。它在“执行”后给了我一个“零”值。

我知道通常请求需要一点时间才能执行,并且认为这可能是 LrHttp 已经在运行而其余代码也在继续运行的问题。因此,我想方设法让 LrHttp 同步运行,但很遗憾没有成功。

下面你们可以看到代码中似乎不起作用的部分——函数 Picsize.login(email, password)。

if doingLogin then return end
doingLogin = true

LrFunctionContext.postAsyncTaskWithContext( 'PICSIZE login',

function( context )

    if not propertyTable.LR_editingExistingPublishConnection then
        notLoggedIn( propertyTable )
    end

    propertyTable.accountStatus = LOC "$$$/Picsize/AccountStatus/LoggingIn=Entrando..."
    propertyTable.loginButtonEnabled = false

    LrDialogs.attachErrorDialogToFunctionContext( context )

    context:addCleanupHandler( function()

        doingLogin = false

        if not storedCredentialsAreValid( propertyTable ) then
            notLoggedIn( propertyTable )
        end

    end )

    local email, password = PicsizeAPI.getCredentials()

    if authRequestDialogResult == 'cancel' then
        return
    end

    propertyTable.accountStatus = LOC "$$$/Picsize/AccountStatus/WaitingForPicsize=Aguardando uma resposta da plataforma PICSIZE..."


    -- this piece seems not to work
    local token = PicsizeAPI.login(email, password)

    if not token then
        return
    end

    local userData = PicsizeAPI.getUserData(token)

    if not userData then
        return
    end

    propertyTable.display_name = userData.display_name
    propertyTable.display_email = userData.display_email
    propertyTable.token = token

    PicsizeUser.updateUserStatusTextBindings( propertyTable )

end )

在 Picsize.login(email, password) 函数中,我们有:

local request = getFormatedRequest(
    '/auth/login',
    { email = email, password = password },
    {{ field = 'Content-Type', value = 'application/json' }}
)

local response, headers = LrHttp.post(request.url, request.body, request.headers)

if response then
    return response.token
else
    return nil
end

如果有人帮助我或提供一些克服它的技巧,我将不胜感激:) 谢谢!

4

0 回答 0