|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object winterwell.jtwitter.OAuthScribeClient
public class OAuthScribeClient
It is recommended that you use OAuthSignpostClient
instead. OAuth
based login using Scribe (http://github.com/fernandezpablo85/scribe). You
need version 0.6.6 of Scribe (or above)!
Example Usage (desktop based):
OAuthScribeClient client = new OAuthScribeClient(JTWITTER_OAUTH_KEY, JTWITTER_OAUTH_SECRET, "oob");
Twitter jtwit = new Twitter("yourtwittername", client);
// open the authorisation page in the user's browser
client.authorizeDesktop();
// get the pin
String v = client.askUser("Please enter the verification PIN from Twitter");
client.setAuthorizationCode(v);
// use the API!
jtwit.setStatus("Messing about in Java");
This is the "officially supported" JTwitter OAuth
client.
,
OAuthHttpClient
Field Summary | |
---|---|
static java.lang.String |
JTWITTER_OAUTH_KEY
This consumer key (and secret) allows you to get up and running fast. |
static java.lang.String |
JTWITTER_OAUTH_SECRET
For use with JTWITTER_OAUTH_KEY |
Constructor Summary | |
---|---|
OAuthScribeClient(java.lang.String consumerKey,
java.lang.String consumerSecret,
java.lang.String callbackUrl)
|
|
OAuthScribeClient(java.lang.String consumerKey,
java.lang.String consumerSecret,
Token accessToken)
Use this if you already have an accessToken for the user. |
Method Summary | |
---|---|
static java.lang.String |
askUser(java.lang.String question)
Convenience method for desktop apps only - does not work in Android |
void |
authorizeDesktop()
Redirect the user's browser to Twitter's authorise page. |
java.net.URI |
authorizeUrl()
|
boolean |
canAuthenticate()
Whether this client is setup to do authentication when contacting the Twitter server. |
java.net.HttpURLConnection |
connect(java.lang.String url,
java.util.Map<java.lang.String,java.lang.String> vars,
boolean b)
Lower-level GET method. |
Twitter.IHttpClient |
copy()
|
Token |
getAccessToken()
|
java.lang.String |
getHeader(java.lang.String headerName)
TODO not implemented yet. |
java.lang.String |
getPage(java.lang.String uri,
java.util.Map<java.lang.String,java.lang.String> vars,
boolean authenticate)
Send an HTTP GET request and return the response body. |
RateLimit |
getRateLimit(Twitter.KRequestType reqType)
|
Token |
getRequestToken()
|
java.lang.String |
post(java.lang.String uri,
java.util.Map<java.lang.String,java.lang.String> vars,
boolean authenticate)
Send an HTTP POST request and return the response body. |
java.net.HttpURLConnection |
post2_connect(java.lang.String uri,
java.util.Map<java.lang.String,java.lang.String> vars)
Lower-level POST method. |
void |
setAuthorizationCode(java.lang.String verifier)
Set the authorisation code (aka the verifier). |
void |
setRetryOnError(boolean retryOnError)
False by default. |
void |
setTimeout(int millisecs)
Deprecated. |
void |
updateRateLimits(Twitter.KRequestType reqType)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String JTWITTER_OAUTH_KEY
public static final java.lang.String JTWITTER_OAUTH_SECRET
JTWITTER_OAUTH_KEY
Constructor Detail |
---|
public OAuthScribeClient(java.lang.String consumerKey, java.lang.String consumerSecret, java.lang.String callbackUrl)
consumerKey
- consumerSecret
- callbackUrl
- Servlet that will get the verifier sent to it, or "oob" for
out-of-band (user copies and pastes the pin /** Opens a popup
dialog asking the user to enter the verification code. (you
would then call setAuthorizationCode(String)
). This
is only relevant when using out-of-band instead of a
callback-url. This is a convenience method -- you will
probably want to build your own UI around this.question
- e.g. "Please enter the authorisation code from Twitter"public OAuthScribeClient(java.lang.String consumerKey, java.lang.String consumerSecret, Token accessToken)
consumerKey
- consumerSecret
- accessToken
- Method Detail |
---|
public static java.lang.String askUser(java.lang.String question)
Convenience method for desktop apps only - does not work in Android
Opens a popup dialog asking the user to enter the verification code. (you would then callsetAuthorizationCode(String)
). This is only
relevant when using out-of-band instead of a callback-url. This is a
convenience method -- you will probably want to build your own UI around
this.
This method requires Swing. It will not work on all devices.
question
- e.g. "Please enter the authorisation code from Twitter"
public void authorizeDesktop()
This method requires Swing. It will not work on all devices.
authorizeUrl()
public java.net.URI authorizeUrl()
public boolean canAuthenticate()
Twitter.IHttpClient
Twitter_Account.verifyCredentials()
if you need to check a
login.
canAuthenticate
in interface Twitter.IHttpClient
public java.net.HttpURLConnection connect(java.lang.String url, java.util.Map<java.lang.String,java.lang.String> vars, boolean b) throws java.io.IOException
Twitter.IHttpClient
connect
in interface Twitter.IHttpClient
java.io.IOException
public Twitter.IHttpClient copy()
copy
in interface Twitter.IHttpClient
public Token getAccessToken()
public java.lang.String getHeader(java.lang.String headerName) throws java.lang.RuntimeException
URLConnectionHttpClient
for
example code.
getHeader
in interface Twitter.IHttpClient
java.lang.RuntimeException
public java.lang.String getPage(java.lang.String uri, java.util.Map<java.lang.String,java.lang.String> vars, boolean authenticate) throws TwitterException
Twitter.IHttpClient
getPage
in interface Twitter.IHttpClient
uri
- The uri to fetchvars
- get arguments to add to the uriauthenticate
- If true, use authentication. The authentication method
used depends on the implementation (basic-auth, OAuth). It
is an error to use true if no authentication details have
been set.
TwitterException
- for a variety of reasons
TwitterException.E404
- for resource-does-not-exist errorspublic RateLimit getRateLimit(Twitter.KRequestType reqType)
getRateLimit
in interface Twitter.IHttpClient
This is where the Twitter
method is implemented.
public Token getRequestToken()
authorizeUrl()
.public java.lang.String post(java.lang.String uri, java.util.Map<java.lang.String,java.lang.String> vars, boolean authenticate) throws TwitterException
Twitter.IHttpClient
post
in interface Twitter.IHttpClient
uri
- The uri to post to.vars
- The form variables to send. These are URL encoded before
sending.authenticate
- If true, send user authentication
TwitterException
- for a variety of reasons
TwitterException.E404
- for resource-does-not-exist errorspublic java.net.HttpURLConnection post2_connect(java.lang.String uri, java.util.Map<java.lang.String,java.lang.String> vars) throws TwitterException
Twitter.IHttpClient
post2_connect
in interface Twitter.IHttpClient
TwitterException
public void setAuthorizationCode(java.lang.String verifier) throws java.lang.RuntimeException
verifier
- a pin code which Twitter gives the user
java.lang.RuntimeException
- Scribe throws an exception if the verifier is invalidpublic void setRetryOnError(boolean retryOnError)
@Deprecated public void setTimeout(int millisecs)
setTimeout
in interface Twitter.IHttpClient
public void updateRateLimits(Twitter.KRequestType reqType)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |