本文整理汇总了Java中oauth.signpost.OAuthProvider.retrieveRequestToken方法的典型用法代码示例。如果您正苦于以下问题:Java OAuthProvider.retrieveRequestToken方法的具体用法?Java OAuthProvider.retrieveRequestToken怎么用?Java OAuthProvider.retrieveRequestToken使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oauth.signpost.OAuthProvider
的用法示例。
在下文中一共展示了OAuthProvider.retrieveRequestToken方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadInBackground
import oauth.signpost.OAuthProvider; //导入方法依赖的package包/类
@Override
public URL loadInBackground() {
NoteblurApplication app = (NoteblurApplication) getContext().getApplicationContext();
OAuthConsumer consumer = app.consumer;
OAuthProvider provider = app.provider;
try {
String authUrl = provider
.retrieveRequestToken(consumer, OAuth.OUT_OF_BAND);
SharedPreferences prefs = getContext().getSharedPreferences("bob", 0);
prefs.edit().putString("TOKEN", consumer.getToken())
.putString("SECRET", consumer.getTokenSecret())
.commit();
return new URL(authUrl);
} catch (Exception e) {
Log.e(TAG, e.getMessage(), e);
throw new RuntimeException(e);
}
}
示例2: doGet
import oauth.signpost.OAuthProvider; //导入方法依赖的package包/类
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// get the provider from the request
Provider provider = OAuthUtilities.getProvider(request);
try {
// see if the request comes with access credentials
Credentials access_credentials = Credentials.getCredentials(request, provider, Credentials.Type.ACCESS);
// prepare the continuation URL that the OAuth provider will redirect the user to
// (we need to make sure this URL points back to this code or the dance will never complete)
String callbackURL = getBaseURL(request,provider);
if (access_credentials == null) {
// access credentials are not available so we need to check
// to see at what stage of the OAuth dance we are
// get the request token credentials
Credentials request_credentials = Credentials.getCredentials(request, provider, Credentials.Type.REQUEST);
OAuthConsumer consumer = OAuthUtilities.getConsumer(request_credentials, provider);
OAuthProvider pp = provider.getProvider();
if (request_credentials == null) {
// no credentials were found, so let's start the dance
// get the request token
String url = pp.retrieveRequestToken(consumer, callbackURL);
request_credentials = new Credentials(consumer.getToken(), consumer.getTokenSecret(), provider);
// and set them to that we can retrieve them later in the second part of the dance
Credentials.setCredentials(request, response, request_credentials, Credentials.Type.REQUEST, 3600);
// now redirect the user to the Authorize URL where she can authenticate against the
// service provider and authorize us.
// The provider will bounce the user back here for us to continue the dance.
response.sendRedirect(url);
} else {
// we are at the second stage of the dance, so we need need to obtain the access credentials now
// if we got here, it means that the user performed a valid authentication against the
// service provider and authorized us, so now we can request more permanent credentials
// to the service provider and save those as well for later use.
// this is set only for OAuth 1.0a
String verificationCode = request.getParameter(OAUTH_VERIFIER_PARAM);
pp.retrieveAccessToken(consumer, verificationCode);
access_credentials = new Credentials(consumer.getToken(), consumer.getTokenSecret(), provider);
// no matter the result, we need to remove the request token
Credentials.deleteCredentials(request, response, provider, Credentials.Type.REQUEST);
Credentials.setCredentials(request, response, access_credentials, Credentials.Type.ACCESS, 30 * 24 * 3600);
finish(response);
}
} else {
finish(response);
}
} catch (Exception e) {
Credentials.deleteCredentials(request, response, provider, Credentials.Type.REQUEST);
Credentials.deleteCredentials(request, response, provider, Credentials.Type.ACCESS);
respondException(response, e);
}
}
示例3: fetchVerification
import oauth.signpost.OAuthProvider; //导入方法依赖的package包/类
/**
* Initiate a verification process.
*
* @param callbackUrl
* the URL, where the user is redirected to, after the verification was
* finished / cancelled
*
* @return
* an instance of {@link Verification} that contains informations about the
* initiated verification process
*
* @throws OAuthException
* if initiation failed
*/
public final Verification fetchVerification( String callbackUrl ) throws OAuthException
{
OAuthConsumer consumer = buildOAuthConsumer( this.consumerToken, this.consumerSecret );
OAuthProvider provider = buildOAuthProvider( this.apiBaseUrl );
String verificationUrl = provider.retrieveRequestToken( consumer, StringUtils.trimToEmpty( callbackUrl ) );
return new Verification( verificationUrl, consumer.getToken(), consumer.getTokenSecret() );
}
示例4: main
import oauth.signpost.OAuthProvider; //导入方法依赖的package包/类
/**
* Main function.
*
* @param args
* command line arguments
*/
public static void main( String[] args ) throws Exception
{
OAuthConsumer consumer =
new DefaultOAuthConsumer( "testzugang-import-api-maklermanagerKey", "VXyCmVpjR4GQVCVBf33T" );
OAuthProvider provider =
new DefaultOAuthProvider( "http://sandbox.immobilienscout24.de/restapi/security/oauth/request_token",
"http://sandbox.immobilienscout24.de/restapi/security/oauth/access_token",
"http://sandbox.immobilienscout24.de/restapi/security/oauth/confirm_access" );
LOGGER.info( "Fetching request token..." );
String authUrl =
provider.retrieveRequestToken( consumer, "http://www.google.de" );
String requestToken = consumer.getToken();
String requestTokenSecret = consumer.getTokenSecret();
LOGGER.info( "Request token: "+requestToken );
LOGGER.info( "Token secret: "+requestTokenSecret );
LOGGER.info( "Now visit:\n"+authUrl
+"\n... and grant this app authorization" );
LOGGER.info( "Enter the verification code and hit ENTER when you're done:" );
BufferedReader br = new BufferedReader( new InputStreamReader( System.in ) );
String verificationCode = br.readLine();
LOGGER.info( "Fetching access token..." );
provider.retrieveAccessToken( consumer, verificationCode.trim() );
String accessToken = consumer.getToken();
String accessTokenSecret = consumer.getTokenSecret();
LOGGER.info( "Access token: "+accessToken );
LOGGER.info( "Token secret: "+accessTokenSecret );
//LOGGER.debug( "first call" );
requestObjectApi( consumer );
//LOGGER.debug( "second call" );
requestObjectApi( consumer );
//LOGGER.debug( "third call" );
OAuthConsumer consumer2 =
new DefaultOAuthConsumer( "testzugang-import-api-maklermanagerKey", "VXyCmVpjR4GQVCVBf33T" );
consumer2.setTokenWithSecret( accessToken, accessTokenSecret );
requestObjectApi( consumer2 );
}