【问题标题】:Running into an error "The Command Text isn't initialized" while debuggingRunning into an error \"The Command Text isn\'t initialized\" while debugging
【发布时间】:2022-12-28 09:46:01
【问题描述】:

I am using this code to perform an OAUTH flow, but it is throwing an error at me: "The Command Text isn't initialized."

// This file contains your Data Connector logic

[Version = "1.0.0"]

section B-------;

[DataSource.Kind="B-------", Publish="B-------.Publish"]

// Login/Auth info

client_id = "-";

client_secret = "-";

username = "-";

password = "-";

redirect_uri = "https://oauth.powerbi.com/views/oauthredirect.html";

state = -;

StartLogin = (resourceURL, state, display) =>

    let

        authorizeURL = "https://auth.*************.com/oauth/authorize?" & Uri.BuildQueryString

        ([
            client_id = client_id,
            response_type = "code",
            response_mode = "query",
            // action = "Login",
            username = username,
            password = password,
            redirect_uri = redirect_uri,
            state = state
        ])
    in
        [
            loginUri = authorizeURL,
            callbackUri = redirect_uri
        ];


FinishLogin = (context, callbackUri, state) =>

    let
        parts = Uri.Parts(callbackUri)[Query],
        result = if(Record.HasFields(parts, {"error", "error_description"})) then
                    error Error.Record(parts[error], parts[error_description], parts)
                else
                    TokenMethod(parts[code], "authorization_code", context)
    in
        result;

TokenMethod = (authCode, grant_type, optional_verifier) =>

    let
        codeParameter = if(grant_type = "authorization_code") then [code = authCode]
                        else [refresh_token = authCode],
        query = codeParameter & 
                [
                    client_id = client_id,
                    client_secret = client_secret,
                    grant_type = grant_type,
                    redirect_uri = redirect_uri
                ],
        tokenResponse = Web.Contents("https://auth.*****************.com/oauth/token?", 
                [
                Content = 
                                                 Text.ToBinary(Uri.BuildQueryString(query)),
                                        Headers = 
                                            [
                                                #"Content-type" = "application/x-www-form- 
                                                                   urlencoded",
                                                #"Accept" = "application/json"
                                            ]
                                    ]),
        parts = Json.Document(tokenResponse)
    in
        if(parts[error]? <> null) then
            error Error.Record(parts[error], parts[message])
        else
            parts;


Refresh = (resourceUrl, refresh_token) => TokenMethod(refresh_token, "refresh_token");


// Data Source Kind description

B------- = (redirect_uri) => [

    Authentication = [

        // Key = [],

        // Username = "-",

        // Password = "-",

        // Windows = [],

        // Anonymous = []

        OAuth = 

        [

            StartLogin = StartLogin,

            FinishLogin = FinishLogin,

            Refresh = Refresh

        ]

    ]

];


// Data Source UI publishing description

B-------.Publish = [

    Beta = true,

    Category = "Other",

    ButtonText = { Extension.LoadString("ButtonTitle"), Extension.LoadString("ButtonHelp") 
},

    LearnMoreUrl = "https://powerbi.microsoft.com/",

    SourceImage = B-------.Icons,

    SourceTypeImage = B-------.Icons

];

B-------.Icons = [

    Icon16 = { Extension.Contents("B-------16.png"), Extension.Contents("B-------20.png"), Extension.Contents("B-------24.png"), Extension.Contents("B-------32.png") },

    Icon32 = { Extension.Contents("B-------32.png"), Extension.Contents("B-------40.png"), Extension.Contents("B-------48.png"), Extension.Contents("B-------64.png") }

];

【问题讨论】:

  • Can you please include a copy of the error message?

标签: powerbi powerquery m


【解决方案1】:

You'll usually get the error like The Command COMMAND isn't initialized. when you have misspelled the function.


For example, this function:

Text.From("This is some text")

Will work successfully:

This is some text.

As shown:


However, when you misspell the function, like this:

Text("This is some text.")

Then you get the error message like this:

Expression.Error: The name 'Text' wasn't recognized.  Make sure it's spelled correctly.

As shown:


So, you should check for some typo's in your script.

    猜你喜欢
    • 2018-11-07
    • 2022-12-19
    • 2022-12-01
    • 2022-12-01
    • 2020-05-13
    • 2021-12-30
    • 2022-12-28
    • 1970-01-01
    • 2022-08-19
    相关资源
    最近更新 更多