Last active
November 30, 2022 14:25
-
-
Save AndyPiddock/b0b7589ff8fc65dd25ada9f80a6e5874 to your computer and use it in GitHub Desktop.
Tsnet Github Gists api access using token #github #gist #api #tsnet #livecode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on mouseUp | |
local tRequestHeaders, tResponseHeaders, tResult, tBytes, tData | |
local tSettings, tCharNo, tUrl | |
put "https://api.github.com/gists" into tUrl | |
-- Build headers for HTTP request | |
put "Accept: application/vnd.github+json" & cr into tRequestHeaders | |
put "User-Agent: LC App" & cr after tRequestHeaders | |
put "Authorization: Bearer <your access token>" & cr after tRequestHeaders | |
--access token from here https://github.com/settings/tokens | |
-- Disable connection re-use if required | |
-- put true into tSettings["no_reuse"] | |
put true into tSettings["save_sent_headers"] | |
put tsNetGetSync(tUrl, tRequestHeaders, tResponseHeaders, tResult, tBytes, tSettings) into tData | |
if the first word of tResult is not "tsneterr:" then | |
-- For HTTP(s) requests, check response code to confirm success or failure | |
if char 1 of tResult is not "2" then | |
answer "HTTP response code" && tResult && "returned from server" | |
end if | |
else | |
answer "Error" && tResult && "returned from server" | |
end if | |
-- At this point: | |
-- tResponseHeaders contains the headers returned from the server | |
-- tRequestHeaders contains the headers that were sent to the server | |
-- tData contains response body | |
put JSONToArray(tData) into tData | |
end mouseUp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment