Widget API headers #1

Closed
opened 2022-01-26 09:35:56 -05:00 by 68267a · 3 comments
68267a commented 2022-01-26 09:35:56 -05:00 (Migrated from github.com)

I'm having trouble getting a widget to display https://icanhasdadjoke.com.

I made a copy of the chuck Norris script but I can't get it to work properly. I think it's because of the http headers. Can I get some hints?

I'm having trouble getting a widget to display https://icanhasdadjoke.com. I made a copy of the chuck Norris script but I can't get it to work properly. I think it's because of the http headers. Can I get some hints?
zobnin commented 2022-01-26 13:08:23 -05:00 (Migrated from github.com)

The original script works perfectly. This means that you made a mistake in your script.

The original script works perfectly. This means that you made a mistake in your script.
68267a commented 2022-01-26 13:45:36 -05:00 (Migrated from github.com)

Yes, I'm asking what I did wrong.

-- name = "dad jokes json"
-- description = "icndb.com"
-- data_source = "icndb.com"
-- type = "widget"
-- author = "me"
-- version = "1.0"

function on_resume()
    http:get("http://icanhasdadjoke.com/slack") 
end

function on_network_result(result)
    joke = ajson:get_value(result, "object object:attachments string:text")
    ui:show_text(joke)
end

function on_click()
    if joke ~= nil then
        system:copy_to_clipboard(joke)
    end
end
Error: Value [{"fallback":"Did you know that protons have mass? I didn't even know they were catholic.","footer":"<https:\/\/icanhazdadjoke.com\/j\/1wkqrcNCljb|permalink> - <https:\/\/icanhazdadjoke.com|icanhazdadjoke.com>","text":"Did you know that protons have mass? I didn't even know they were catholic."}] at attachments of type org.json.JSONArray cannot be converted to JSONObject
Yes, I'm asking what I did wrong. ``` -- name = "dad jokes json" -- description = "icndb.com" -- data_source = "icndb.com" -- type = "widget" -- author = "me" -- version = "1.0" function on_resume() http:get("http://icanhasdadjoke.com/slack") end function on_network_result(result) joke = ajson:get_value(result, "object object:attachments string:text") ui:show_text(joke) end function on_click() if joke ~= nil then system:copy_to_clipboard(joke) end end ``` ``` Error: Value [{"fallback":"Did you know that protons have mass? I didn't even know they were catholic.","footer":"<https:\/\/icanhazdadjoke.com\/j\/1wkqrcNCljb|permalink> - <https:\/\/icanhazdadjoke.com|icanhazdadjoke.com>","text":"Did you know that protons have mass? I didn't even know they were catholic."}] at attachments of type org.json.JSONArray cannot be converted to JSONObject ```
zobnin commented 2022-01-27 00:55:26 -05:00 (Migrated from github.com)

You are parsing JSON incorrectly. Here is the correct line:

joke = ajson:get_value(result, "object array:attachments object:0 string:text")

You are parsing JSON incorrectly. Here is the correct line: `joke = ajson:get_value(result, "object array:attachments object:0 string:text")`
Sign in to join this conversation.
No description provided.