I like Twitter... Enjoy ;-)
Posted: Fri Jan 30, 2015 5:31 pm
/*
twitter, libTwitter
Version 1.0 Jean-Marc QUERE, @codyssea
30th January 2015
inspired by "How to use Twitter OAuth v1.1 with JavaScript/jQuery"
Mike Rogers, @MikeRogers0
hmacSha1, libHash-Hmac
Version 2.3 Mark Smith, mark@maseurope.net
9th September 2009
*/
function arrayMerge pArray1,pArray2
local pArray
put pArray1 into pArray
repeat for each line tKey in the keys of pArray2
put pArray2[tKey] into pArray[tKey]
end repeat
return pArray
end arrayMerge
function buildBaseString pBaseUrl, pMethod,pParams
local tResult
get the keys of pParams
sort lines of it
repeat for each line tKey in it
put tKey & "%3D" & urlencode(pParams[tKey]) & "%26" after tResult
end repeat
put char 1 to -4 of tResult into tResult
return pMethod & "&" & urlencode(pBaseUrl) & "&" & tResult
end buildBaseString
function hmacSha1 pMsg, pKey
if length(pKey) > 64 then put sha1digest(pKey) into pKey
repeat 64 - length(pKey)
put null after pKey
end repeat
repeat for each byte c in pKey
put numtobyte(bytetonum(c) bitXor 54) after ipad
put numtobyte(bytetonum(c) bitXor 92) after opad
end repeat
return sha1digest(opad & sha1digest(ipad & pMsg))
end hmacSha1
function buildAuthorizationHeader pOAuth
local tResult
put "Authorization: OAuth " into tResult
repeat for each line tKey in the keys of pOAuth
put tKey & "=" & quote & urlencode(pOAuth[tKey]) & quote & comma & space after tResult
end repeat
return char 1 to -3 of tResult
end buildAuthorizationHeader
function twitter pUrl
local tTwitter
put "--- put your token here -------------" into tTwitter["oauth_access_token"]
put "--- put your secret token here ------" into tTwitter["oauth_access_token_secret"]
put "--- put your consumer key here ------" into tTwitter["consumer_key"]
put "--- put your consumer secret here ---" into tTwitter["consumer_secret"]
put "https://api.twitter.com/1.1/" into tTwitter["base_url"]
local tUrlParts
put pUrl into tUrlParts
split tUrlParts by "?"
-- tUrlParts[1] : path, tUrlParts[2]: query
local tUrlArguments
put tUrlParts[2] into tUrlArguments
split tUrlArguments by "&" and "="
local tFullUrl
put tTwitter["base_url"] & pUrl into tFullUrl
local tBaseUrl
put tTwitter["base_url"] & tUrlParts[1] into tBaseUrl
local tTime
put the internet date into tTime
convert tTime to seconds
local tOAuth
put "1.0" into tOAuth["oauth_version"]
put tTwitter["consumer_key"] into tOAuth["oauth_consumer_key"]
put tTime into tOAuth["oauth_nonce"]
put "HMAC-SHA1" into tOAuth["oauth_signature_method"]
put tTwitter["oauth_access_token"] into tOAuth["oauth_token"]
put tTime into tOAuth["oauth_timestamp"]
local tBaseInfo
put buildBaseString(tBaseUrl,"GET",arrayMerge(tOAuth,tUrlArguments)) into tBaseInfo
local tCompositeKey
put urlencode(tTwitter["consumer_secret"]) & "&" & urlencode(tTwitter["oauth_access_token_secret"]) into tCompositeKey
put base64Encode(hmacSha1( tBaseInfo, tCompositeKey)) into tOAuth["oauth_signature"]
set the httpHeaders to buildAuthorizationHeader(tOAuth)
return url(tFullUrl)
end twitter
/* sample : put a json response in the field "fldTweets"
on mouseUp
put twitter("statuses/user_timeline.json?screen_name=codyssea&count=10&include_rts=false&exclude_replies=true") into field "fldTweets"
end mouseUp
*/
twitter, libTwitter
Version 1.0 Jean-Marc QUERE, @codyssea
30th January 2015
inspired by "How to use Twitter OAuth v1.1 with JavaScript/jQuery"
Mike Rogers, @MikeRogers0
hmacSha1, libHash-Hmac
Version 2.3 Mark Smith, mark@maseurope.net
9th September 2009
*/
function arrayMerge pArray1,pArray2
local pArray
put pArray1 into pArray
repeat for each line tKey in the keys of pArray2
put pArray2[tKey] into pArray[tKey]
end repeat
return pArray
end arrayMerge
function buildBaseString pBaseUrl, pMethod,pParams
local tResult
get the keys of pParams
sort lines of it
repeat for each line tKey in it
put tKey & "%3D" & urlencode(pParams[tKey]) & "%26" after tResult
end repeat
put char 1 to -4 of tResult into tResult
return pMethod & "&" & urlencode(pBaseUrl) & "&" & tResult
end buildBaseString
function hmacSha1 pMsg, pKey
if length(pKey) > 64 then put sha1digest(pKey) into pKey
repeat 64 - length(pKey)
put null after pKey
end repeat
repeat for each byte c in pKey
put numtobyte(bytetonum(c) bitXor 54) after ipad
put numtobyte(bytetonum(c) bitXor 92) after opad
end repeat
return sha1digest(opad & sha1digest(ipad & pMsg))
end hmacSha1
function buildAuthorizationHeader pOAuth
local tResult
put "Authorization: OAuth " into tResult
repeat for each line tKey in the keys of pOAuth
put tKey & "=" & quote & urlencode(pOAuth[tKey]) & quote & comma & space after tResult
end repeat
return char 1 to -3 of tResult
end buildAuthorizationHeader
function twitter pUrl
local tTwitter
put "--- put your token here -------------" into tTwitter["oauth_access_token"]
put "--- put your secret token here ------" into tTwitter["oauth_access_token_secret"]
put "--- put your consumer key here ------" into tTwitter["consumer_key"]
put "--- put your consumer secret here ---" into tTwitter["consumer_secret"]
put "https://api.twitter.com/1.1/" into tTwitter["base_url"]
local tUrlParts
put pUrl into tUrlParts
split tUrlParts by "?"
-- tUrlParts[1] : path, tUrlParts[2]: query
local tUrlArguments
put tUrlParts[2] into tUrlArguments
split tUrlArguments by "&" and "="
local tFullUrl
put tTwitter["base_url"] & pUrl into tFullUrl
local tBaseUrl
put tTwitter["base_url"] & tUrlParts[1] into tBaseUrl
local tTime
put the internet date into tTime
convert tTime to seconds
local tOAuth
put "1.0" into tOAuth["oauth_version"]
put tTwitter["consumer_key"] into tOAuth["oauth_consumer_key"]
put tTime into tOAuth["oauth_nonce"]
put "HMAC-SHA1" into tOAuth["oauth_signature_method"]
put tTwitter["oauth_access_token"] into tOAuth["oauth_token"]
put tTime into tOAuth["oauth_timestamp"]
local tBaseInfo
put buildBaseString(tBaseUrl,"GET",arrayMerge(tOAuth,tUrlArguments)) into tBaseInfo
local tCompositeKey
put urlencode(tTwitter["consumer_secret"]) & "&" & urlencode(tTwitter["oauth_access_token_secret"]) into tCompositeKey
put base64Encode(hmacSha1( tBaseInfo, tCompositeKey)) into tOAuth["oauth_signature"]
set the httpHeaders to buildAuthorizationHeader(tOAuth)
return url(tFullUrl)
end twitter
/* sample : put a json response in the field "fldTweets"
on mouseUp
put twitter("statuses/user_timeline.json?screen_name=codyssea&count=10&include_rts=false&exclude_replies=true") into field "fldTweets"
end mouseUp
*/