本文整理汇总了Java中com.github.scribejava.core.builder.ServiceBuilder类的典型用法代码示例。如果您正苦于以下问题:Java ServiceBuilder类的具体用法?Java ServiceBuilder怎么用?Java ServiceBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ServiceBuilder类属于com.github.scribejava.core.builder包,在下文中一共展示了ServiceBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.github.scribejava.core.builder.ServiceBuilder; //导入依赖的package包/类
public static void main (String[] args) {
ResourceBundle secrets = ResourceBundle.getBundle("facebookutil/secret");
final OAuth20Service service = new ServiceBuilder()
.apiKey(secrets.getString("clientId"))
.apiSecret(secrets.getString("clientSecret"))
.callback("https://duke.edu/")
.grantType("client_credentials")
.build(FacebookApi.instance());
String url = "https://graph.facebook.com/oauth/access_token?";
url = url + "&client_id" + "=" + secrets.getString("clientId");
url = url + "&client_secret" + "=" + secrets.getString("clientSecret");
url = url + "&grant_type" + "=" + "client_credentials";
final OAuthRequest request =
new OAuthRequest(Verb.GET, url, service);
service.signRequest(new OAuth2AccessToken(""), request);
System.out.println(request.getBodyContents());
System.out.println(request.getUrl());
Response response = request.send();
System.out.println(response.getBody());
}
示例2: facebookExample
import com.github.scribejava.core.builder.ServiceBuilder; //导入依赖的package包/类
public void facebookExample () {
// Replace these with your client id and secret
final String clientId = mySecrets.getString("facebookId");
final String clientSecret = mySecrets.getString("facebookSecret");
service = new ServiceBuilder()
.apiKey(clientId)
.apiSecret(clientSecret)
.callback(CALLBACK_URL)
// .grantType("client_credentials")
.scope("publish_actions,email,public_profile")
// .scope("publish_actions")
.build(FacebookApi.instance());
System.out.println();
// Obtain the Authorization URL
System.out.println("Fetching the Authorization URL...");
final String authorizationUrl = service.getAuthorizationUrl();
myPage.getEngine().load(authorizationUrl);
}
示例3: twitterExample
import com.github.scribejava.core.builder.ServiceBuilder; //导入依赖的package包/类
public void twitterExample () {
final String clientId = mySecrets.getString("twitterId");
final String clientSecret = mySecrets.getString("twitterSecret");
final OAuth10aService service = new ServiceBuilder()
.apiKey(clientId)
.apiSecret(clientSecret)
.grantType("client_credentials")
.build(TwitterApi.instance());
System.out.println("=== Twitter's OAuth Workflow ===");
System.out.println();
twitterToken = service.getRequestToken();
// Obtain the Authorization URL
System.out.println("Fetching the Authorization URL...");
System.out.println("request: " + twitterToken.toString());
final String authorizationUrl = service.getAuthorizationUrl(twitterToken);
myPage.getEngine().load(authorizationUrl);
}
示例4: googleExample
import com.github.scribejava.core.builder.ServiceBuilder; //导入依赖的package包/类
public void googleExample () {
// Replace these with your client id and secret
final String clientId = mySecrets.getString("googleId");
final String clientSecret = mySecrets.getString("googleSecret");
service = new ServiceBuilder()
.apiKey(clientId)
.apiSecret(clientSecret)
.callback(CALLBACK_URL)
// .scope("https://www.googleapis.com/auth/plus.login ")
.scope("https://www.googleapis.com/auth/plus.circles.write https://www.googleapis.com/auth/plus.circles.read https://www.googleapis.com/auth/plus.stream.write https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/plus.stream.read")
.build(GoogleApi20.instance());
System.out.println();
// Obtain the Authorization URL
System.out.println("Fetching the Authorization URL...");
final String authorizationUrl = service.getAuthorizationUrl();
myPage.getEngine().load(authorizationUrl);
}
示例5: Auth
import com.github.scribejava.core.builder.ServiceBuilder; //导入依赖的package包/类
public Auth(String clientId, String clientSecret, String callbackURL) throws NoSuchAlgorithmException {
this.clientId = clientId;
this.clientSecret = clientSecret;
this.gson = new Gson();
this.authUsers = new ArrayList<>();
// TODO: this is where authorized users are hardcoded
// The email address must be one managed by Google
//authUsers.add("[email protected]");
this.globalService = new ServiceBuilder()
.apiKey(clientId)
.apiSecret(clientSecret)
.scope("email") // replace with desired scope
.callback(callbackURL)
.build(GoogleApi20.instance());
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
keyPairGenerator.initialize(2048);
this.keyPair = keyPairGenerator.genKeyPair();
this.callbackURL = callbackURL;
}
示例6: getAuthURL
import com.github.scribejava.core.builder.ServiceBuilder; //导入依赖的package包/类
/**
* @return A string containing a URL that we can send visitors to in order to authenticate them
*/
public String getAuthURL(String originatingURL){
// I think we have to create a new service for every request we send out
// since each one needs a different secretState
final OAuth20Service service = new ServiceBuilder()
.apiKey(clientId)
.apiSecret(clientSecret)
.scope("email") // replace with desired scope
.state(generateSharedGoogleSecret(originatingURL))
.callback(callbackURL)
.build(GoogleApi20.instance());
final Map<String, String> additionalParams = new HashMap<>();
additionalParams.put("access_type", "offline");
additionalParams.put("prompt", "consent");
final String authorizationUrl = service.getAuthorizationUrl(additionalParams);
return authorizationUrl;
}
示例7: onCreate
import com.github.scribejava.core.builder.ServiceBuilder; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_log_in_to_ttn);
clientId = getString(R.string.oauth_client_id);
clientSecret = getString(R.string.oauth_client_secret);
redirectURI = getString(R.string.oauth_redirect_url);
service = new ServiceBuilder()
.apiKey(clientId)
.apiSecret(clientSecret)
.state(secretState)
.callback(redirectURI)
.build(TheThingsNetworkOathApi.instance());
MyApplication mApplication = (MyApplication)getApplicationContext();
mApplication.ttnApplications = new ArrayList<>();
mApplication.chosenTtnApplication = null;
Answers.getInstance().logCustom(new CustomEvent("Device configure").putCustomAttribute("method", "oauth2"));
loadLoginPage();
}
示例8: getService
import com.github.scribejava.core.builder.ServiceBuilder; //导入依赖的package包/类
/**
* Gets the OAuth Service.
*
* @return the OAuth Service
*/
@SuppressWarnings("unchecked")
public OAuthService getService() {
if (this.service == null){
if (config.getScope().length()>0){
this.service = new ServiceBuilder().provider(config.getApiClass())
.apiKey(config.getApiKey())
.apiSecret(config.getApiSecret())
.callback(config.getCallback())
.scope(config.getScope())
.build();
}
else {
this.service = new ServiceBuilder().provider(config.getApiClass())
.apiKey(config.getApiKey())
.apiSecret(config.getApiSecret())
.callback(config.getCallback())
.build();
}
}
return service;
}
示例9: doInBackground
import com.github.scribejava.core.builder.ServiceBuilder; //导入依赖的package包/类
protected AccountData doInBackground(Void... voids) {
AccountData aData = new AccountData();
//Build the OAuth service
final OAuth10aService service = new ServiceBuilder()
.apiKey(apiKeys.CONSUMER_KEY)
.apiSecret(apiKeys.CONSUMER_SECRET)
.build(TradeKingApi.instance());
Token accessToken = new Token(apiKeys.OAUTH_TOKEN, apiKeys.OAUTH_TOKEN_SECRET);
// Fetch the JSON data
OAuthRequest request = new OAuthRequest(Verb.GET, tk.getFullAccountInfo(), service);
service.signRequest(accessToken, request);
Response response = request.send();
//parse json
try {
aData = parseJSON(response);
} catch (JSONException e) {
e.printStackTrace();
aData.setError(e.toString());
}
return aData;
}
示例10: doInBackground
import com.github.scribejava.core.builder.ServiceBuilder; //导入依赖的package包/类
protected StockQuote doInBackground(Void... voids){
//pause for a second so we don't get rate limited
SystemClock.sleep(1000);
//Build the OAuth service
final OAuth10aService service = new ServiceBuilder()
.apiKey(apiKeys.CONSUMER_KEY)
.apiSecret(apiKeys.CONSUMER_SECRET)
.build(TradeKingApi.instance());
Token accessToken = new Token(apiKeys.OAUTH_TOKEN, apiKeys.OAUTH_TOKEN_SECRET);
// Fetch the JSON data
OAuthRequest request = new OAuthRequest(Verb.GET, tk.getMarketQuote(symbol), service);
service.signRequest(accessToken, request);
Response response = request.send();
StockQuote quote = new StockQuote(symbol);
try {
quote = parseJSON(response);
} catch (JSONException e) {
e.printStackTrace();
quote.setError(e.toString());
}
return quote;
}
示例11: doInBackground
import com.github.scribejava.core.builder.ServiceBuilder; //导入依赖的package包/类
protected Double doInBackground(Void... voids){
double ret = 0.0;
//Build the OAuth service
final OAuth10aService service = new ServiceBuilder()
.apiKey(apiKeys.CONSUMER_KEY)
.apiSecret(apiKeys.CONSUMER_SECRET)
.build(TradeKingApi.instance());
Token accessToken = new Token(apiKeys.OAUTH_TOKEN, apiKeys.OAUTH_TOKEN_SECRET);
// Fetch the JSON data
OAuthRequest request = new OAuthRequest(Verb.GET, tk.getOptionStrikePrices(symbol), service);
service.signRequest(accessToken, request);
Response response = request.send();
try {
ret = parseJSON(response);
} catch (JSONException e) {
e.printStackTrace();
}
return ret;
}
示例12: doInBackground
import com.github.scribejava.core.builder.ServiceBuilder; //导入依赖的package包/类
protected OptionOrder doInBackground(Void... voids){
OptionOrder order = new OptionOrder();
//Build the OAuth service
final OAuth10aService service = new ServiceBuilder()
.apiKey(apiKeys.CONSUMER_KEY)
.apiSecret(apiKeys.CONSUMER_SECRET)
.build(TradeKingApi.instance());
Token accessToken = new Token(apiKeys.OAUTH_TOKEN, apiKeys.OAUTH_TOKEN_SECRET);
// Fetch the JSON data
OAuthRequest request = new OAuthRequest(Verb.POST, tk.getMarketOptionLive(), service);
//request.addHeader("TKI_OVERRIDE", "true");
request.addPayload(fixml.getLimitFixmlString());
service.signRequest(accessToken, request);
Response response = request.send();
try {
order = parseJSON(response);
} catch (JSONException e) {
e.printStackTrace();
order.setError(e.toString());
}
return order;
}
示例13: doInBackground
import com.github.scribejava.core.builder.ServiceBuilder; //导入依赖的package包/类
protected OptionOrderPreview doInBackground(Void... voids){
OptionOrderPreview order = new OptionOrderPreview();
//Build the OAuth service
final OAuth10aService service = new ServiceBuilder()
.apiKey(apiKeys.CONSUMER_KEY)
.apiSecret(apiKeys.CONSUMER_SECRET)
.build(TradeKingApi.instance());
Token accessToken = new Token(apiKeys.OAUTH_TOKEN, apiKeys.OAUTH_TOKEN_SECRET);
// Fetch the JSON data
OAuthRequest request = new OAuthRequest(Verb.POST, tk.getMarketOptionPreview(), service);
request.addPayload(fixml.getMarketFixmlString());
service.signRequest(accessToken, request);
Response response = request.send();
try {
order = parseJSON(response);
} catch (JSONException e) {
e.printStackTrace();
order.setError(e.toString());
}
return order;
}
示例14: doGet
import com.github.scribejava.core.builder.ServiceBuilder; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String providerName = StringUtils.substringAfterLast(req.getRequestURI(), "/");
LOGGER.info("Authz request for provider: [{}]", providerName);
OAuthProvider provider = this.providerFactory.getProvider(providerName);
LOGGER.info("OAuthProvider: [{}]", provider);
OAuth20Service oauth2Service = this.providerFactory.getOAuth2Service(providerName);
if (oauth2Service == null) {
oauth2Service = new ServiceBuilder().apiKey(provider.getApiKey()).apiSecret(provider.getApiSecret())
.callback(provider.getCallbackURL()).build(provider.getApi());
this.providerFactory.addOAuth2Service(providerName, oauth2Service);
}
String authorizationUrl = oauth2Service.getAuthorizationUrl();
LOGGER.info("Authz URL: [{}]", authorizationUrl);
resp.sendRedirect(authorizationUrl);
}
示例15: login
import com.github.scribejava.core.builder.ServiceBuilder; //导入依赖的package包/类
@RequestMapping("/login")
public OAuthResponse login()
{
UUID uuid = UUID.randomUUID();
State state = new State();
state.setUuid(uuid);
state.setApiVersion(RuneLiteAPI.getVersion());
OAuth20Service service = new ServiceBuilder()
.apiKey(oauthClientId)
.apiSecret(oauthClientSecret)
.scope(SCOPE)
.callback(RL_OAUTH_URL)
.state(gson.toJson(state))
.build(GoogleApi20.instance());
String authorizationUrl = service.getAuthorizationUrl();
OAuthResponse lr = new OAuthResponse();
lr.setOauthUrl(authorizationUrl);
lr.setUid(uuid);
return lr;
}