-
Notifications
You must be signed in to change notification settings - Fork 4
/
README
55 lines (44 loc) · 2.44 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
Scala OAuth is a simple OAuth client library written in Scala. The focus is on
simplicity for common tasks moreso than supporting everything you might ever
want to do with OAuth.
Use it, clone it and continue development, etc. as you like within the bounds
of the license. New requests to pull patches may or may not ever get
completed. I enjoy developing new things and learning from them for a hobby,
not supporting them afterwards, so I'll have moved on to new projects.
I wanted to put this code out here so that it is easily accessible for anyone
who might be able to use it, though.
Thanks for taking a look and I hope you find it useful.
Authors:
Justin Michalicek
Usage Example:
import jm.oauth.OAuth
import jm.oauth.Requester
val oauthApiUrl = TWITTER_REQUEST_TOKEN_URL
val oauthConsumerKey = TWITTER_CONSUMER_KEY
val oauthConsumerSecret = TWITTER_CONSUMER_SECRET
//Getting the request token
val oauth = new OAuth(OAuth.POST, oauthConsumerSecret, oauthConsumerKey, OAuth.HMAC_SHA1)
val requestToken = oauth.generateRequestToken(oauthApiUrl, OAuth.OOB)
//careful, different OAuth services return slightly different name/value pairs.
println("request_token is " + requestToken)
println(requestToken("oauth_token_secret"))
/Getting the access token now that you have a request token
/*oauth.generateAccessToken(accessTokenUrl, oauth_token_secret, oauth_token,
* oauth_verifier or pin) Since this example is using OOB rather than a
* callback URL and Twitter, the user must now to go the url
* https://api.twitter.com/oauth/authorize?oauth_token=tokenrequest("oauth_token")
* where they will sign in and be presented with a PIN to use in the next step.
* If using a callback url, an identifier will be included there.
*/
val accessTokenRequest = oauth.generateAccessToken(accessTokenUrl,
tokenRequest("oauth_token_secret"), tokenRequest("oauth_token"), PIN)
/* Now store the authorized token and authorized token secret somewhere
* With twitter these will be tokenRequest("oauth_token") for authorized token
* and tokenRequest("oauth_token_secret") for the authorized token secret
*/
//Make a request - posting an update to Twitter here
val requester = new Requester(OAuth.HMAC_SHA1, TWITTER_CONSUMER_SECRET,
TWITTER_CONSUMER_KEY, TWITTER_AUTHORIZED_TOKEN, TWITTER_AUTHORIZED_TOKEN_SECRET)
val postMessage = Map("status" -> "another test")
//response is a byte array
val response = requester.post("http://api.twitter.com/1/statuses/update.json", postMessage)