Skip to content

Instantly share code, notes, and snippets.

@neetsdkasu
Created May 16, 2017 23:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neetsdkasu/4b2418c89fea4c62c90029952f79e0cd to your computer and use it in GitHub Desktop.
Save neetsdkasu/4b2418c89fea4c62c90029952f79e0cd to your computer and use it in GitHub Desktop.
【練習】ツイッターでツイート成功した ( with https://gist.github.com/neetsdkasu/19f9703f8167213708f751c1c2347599 )
// test
// author: Leonardone @ NEETSDKASU
open neetsdkasu.Twitter
let consumerToken = {
Key = "key";
Secret = "secret"
}
let oauthToken = {
Key = "key";
Secret = "secret"
}
let pinCode = "0000000"
let accessToken = {
Key = "key";
Secret = "secret"
}
let status = "Success! This tweet posted by usakdsteen App!!"
[<EntryPoint>]
let main _ =
use client = new Client(consumerToken, "oob")
// match OAuth.requestToken client with
// match OAuth.accessToken client oauthToken pinCode with
match REST.statusUpdate client accessToken status with
| Some(s) -> printfn "%s" s
| None -> printfn "failed"
0
// Twitter.REST
// author: Leonardone @ NEETSDKASU
namespace neetsdkasu.Twitter
module REST =
let pair name value = (name, value)
let toOAuthParam =
(+) "OAuth "
<< String.concat ", "
<< List.map (function
(k, v) ->
k + "=\"" + Utility.percentEncode v + "\""
)
let statusUpdateApi = "https://api.twitter.com/1.1/statuses/update.json"
let statusUpdate (client: Client) accessToken status =
let escapedStatus = Utility.percentEncode status
let param = [ pair "oauth_consumer_key" client.ConsumerToken.Key
; pair "oauth_nonce" (Utility.nonce())
; pair "oauth_signature_method" "HMAC-SHA1"
; pair "oauth_timestamp" (string <| Utility.now() + 10u)
; pair "oauth_version" "1.0"
; pair "oauth_token" accessToken.Key
]
let signature = Utility.signature
"POST" statusUpdateApi (("status", status) :: param)
client.ConsumerToken.Secret accessToken.Secret
let oauthParam = toOAuthParam (("oauth_signature", signature) :: param)
do client.WebClient.Headers.Add("Authorization", oauthParam)
try
let url = statusUpdateApi + "?status=" + escapedStatus
let res = client.WebClient.UploadData(url, Array.empty)
Some(client.WebClient.Encoding.GetString(res))
with
ex ->
eprintf "%A" ex
None
@neetsdkasu
Copy link
Author

POSTなのにGETみたいにURLにツイート内容含めるの何なの・・・

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment