本文整理汇总了Java中com.github.scribejava.core.model.Response类的典型用法代码示例。如果您正苦于以下问题:Java Response类的具体用法?Java Response怎么用?Java Response使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Response类属于com.github.scribejava.core.model包,在下文中一共展示了Response类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.github.scribejava.core.model.Response; //导入依赖的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: validate
import com.github.scribejava.core.model.Response; //导入依赖的package包/类
@Override
public CredentialValidationResult validate(Credential credential) {
if (credential instanceof TokenResponseCredential) {
TokenResponseCredential tokenCredential = (TokenResponseCredential) credential;
OAuthRequest request = new OAuthRequest(Verb.GET, "https://www.googleapis.com/oauth2/v3/userinfo");
OAuth20Service service = tokenCredential.getService();
OAuth2AccessToken token = tokenCredential.getTokenResponse();
service.signRequest(token, request);
try {
Response oResp = service.execute(request);
String body = oResp.getBody();
OAuth2User oAuth2User = jsonProcessor.extractUserInfo(body);
return new CredentialValidationResult(oAuth2User);
} catch (InterruptedException | ExecutionException | IOException e) {
e.printStackTrace(); // FIXME
}
}
return CredentialValidationResult.NOT_VALIDATED_RESULT;
}
示例3: sendRequestForData
import com.github.scribejava.core.model.Response; //导入依赖的package包/类
/**
* Make a request to get the data of the authenticated user for the provider.
*
* @param accessToken the access token
* @param dataUrl url of the data
* @param verb method used to request data
* @return the user data response
*/
protected CompletableFuture<String> sendRequestForData(final T accessToken, final String dataUrl, Verb verb) {
logger.debug("accessToken: {} / dataUrl: {}", accessToken, dataUrl);
final long t0 = System.currentTimeMillis();
final OAuthRequestAsync request = createOAuthRequest(dataUrl, verb);
signRequest(accessToken, request);
final CompletableFuture<Response> responseFuture = new CompletableFuture<>();
request.sendAsync(ScribeCallbackAdapter.toScribeOAuthRequestCallback(responseFuture));
return responseFuture.thenApply(response -> {
final int code = response.getCode();
final String body;
try {
body = response.getBody();
} catch (final IOException ex) {
throw new HttpCommunicationException("Error getting body: " + ex.getMessage());
}
final long t1 = System.currentTimeMillis();
logger.debug("Request took: " + (t1 - t0) + " ms for: " + dataUrl);
logger.debug("response code: {} / response body: {}", code, body);
if (code != 200) {
throw new HttpCommunicationException(code, body);
}
return body;
});
}
示例4: sendRequestForData
import com.github.scribejava.core.model.Response; //导入依赖的package包/类
/**
* Make a request to get the data of the authenticated user for the provider.
*
* @param accessToken the access token
* @param dataUrl url of the data
* @return the user data response
*/
protected String sendRequestForData(final T accessToken, final String dataUrl) {
logger.debug("accessToken: {} / dataUrl: {}", accessToken, dataUrl);
final long t0 = System.currentTimeMillis();
final OAuthRequest request = createOAuthRequest(dataUrl);
signRequest(accessToken, request);
final Response response = request.send();
final int code = response.getCode();
final String body = response.getBody();
final long t1 = System.currentTimeMillis();
logger.debug("Request took: " + (t1 - t0) + " ms for: " + dataUrl);
logger.debug("response code: {} / response body: {}", code, body);
if (code != 200) {
throw new HttpCommunicationException(code, body);
}
return body;
}
示例5: loadOAuthProviderAccount
import com.github.scribejava.core.model.Response; //导入依赖的package包/类
public OAuthProviderAccount loadOAuthProviderAccount(Token accessToken, OAuthProviderName provider) {
OAuthService service = this.getService();
// getting user profile
OAuthRequest oauthRequest = new OAuthRequest(Verb.GET, config.getProfileUrl(), service);
service.signRequest(accessToken, oauthRequest); // the access token from step 4
Response oauthResponse = oauthRequest.send();
String jsonString = oauthResponse.getBody();
JSONObject root = new JSONObject(jsonString);
String accountId = String.valueOf(root.getInt(TWITTER_ACCTID_PROPERTY));
String displayName = root.getString(TWITTER_DISPLAYNAME_PROPERTY);
String publicId = root.getString(TWITTER_SCREENNAME_PROPERTY);
String profilePath = provider.getIdProviderUrl() + "/" + publicId;
OAuthProviderAccount profile =
new OAuthProviderAccount(accessToken, provider, displayName, accountId, publicId , profilePath);
return profile;
}
示例6: doInBackground
import com.github.scribejava.core.model.Response; //导入依赖的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;
}
示例7: parseJSON
import com.github.scribejava.core.model.Response; //导入依赖的package包/类
private AccountData parseJSON(Response response) throws JSONException{
AccountData accountData = new AccountData();
JSONObject json = new JSONObject();
JSONObject jsonResponse = new JSONObject();
JSONObject jsonAccountBal = new JSONObject();
JSONObject jsonMoney = new JSONObject();
JSONObject jsonSecurities = new JSONObject();
JSONObject jsonBuyPower = new JSONObject();
json = new JSONObject(response.getBody());
jsonResponse = json.getJSONObject(GET_RESPONSE);
jsonAccountBal = jsonResponse.getJSONObject(GET_ACCOUNT_BAL);
jsonMoney = jsonAccountBal.getJSONObject(GET_MONEY);
jsonSecurities = jsonAccountBal.getJSONObject(GET_SECURITIES);
jsonBuyPower = jsonAccountBal.getJSONObject(GET_BUYING_POWER);
accountData.setCashAvailable(jsonMoney.getDouble("cashavailable"));
accountData.setAccountValue(jsonAccountBal.getDouble("accountvalue"));
accountData.setUnsettledFunds(jsonMoney.getDouble("unsettledfunds"));
accountData.setOptionValue(jsonSecurities.getDouble("options"));
accountData.setStockValue(jsonSecurities.getDouble("stocks"));
accountData.setUnclearedDeposits(jsonMoney.getDouble("uncleareddeposits"));
//accountData.setBuyingPower(jsonBuyPower.getDouble("options"));
return accountData;
}
示例8: doInBackground
import com.github.scribejava.core.model.Response; //导入依赖的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;
}
示例9: parseJSON
import com.github.scribejava.core.model.Response; //导入依赖的package包/类
public StockQuote parseJSON(Response response) throws JSONException{
StockQuote quote = new StockQuote(symbol);
JSONObject jsonResponse = new JSONObject();
JSONObject jsonQuotes = new JSONObject();
JSONObject jsonQuote = new JSONObject();
JSONObject json = new JSONObject(response.getBody());
jsonResponse = json.getJSONObject(GET_RESPONSE);
jsonQuotes = jsonResponse.getJSONObject(GET_QUOTES);
jsonQuote = jsonQuotes.getJSONObject(GET_QUOTE);
quote.setStockQuoteData(
jsonQuote.getDouble("last"),
jsonQuote.getDouble("ask"),
jsonQuote.getDouble("asksz"),
jsonQuote.getDouble("bid"),
jsonQuote.getDouble("bidsz"),
jsonQuote.getDouble("hi"),
jsonQuote.getDouble("lo"),
jsonQuote.getLong("vl"),
jsonQuote.getLong("incr_vl"),
jsonQuote.getLong("timestamp"));
return quote;
}
示例10: parseJSON
import com.github.scribejava.core.model.Response; //导入依赖的package包/类
private MarketDay parseJSON(Response response) throws JSONException {
MarketDay marketDay = new MarketDay();
JSONObject json = new JSONObject();
JSONObject jsonResponse = new JSONObject();
JSONObject jsonQuotes = new JSONObject();
JSONArray jsonQuote = new JSONArray();
//Make sure to respect the object(array(object)) hierarchy of the response.
json = new JSONObject(response.getBody());
jsonResponse = json.getJSONObject(GET_RESPONSE);
jsonQuotes = jsonResponse.getJSONObject(GET_QUOTES);
jsonQuote = jsonQuotes.getJSONArray(GET_QUOTE);
//Loop through the quote array and do something with the data..
for (int i = 0; i < jsonQuote.length(); i++){
JSONObject curQuote = jsonQuote.getJSONObject(i);
marketDay.addCandle(1,
curQuote.getDouble("opn"),
curQuote.getDouble("lo"),
curQuote.getDouble("hi"),
curQuote.getDouble("last"),
curQuote.getLong("incr_vl"));
}
return marketDay;
}
示例11: parseJSON
import com.github.scribejava.core.model.Response; //导入依赖的package包/类
public ArrayList<String> parseJSON(Response response) throws JSONException{
ArrayList<String> ret = new ArrayList<String>();
JSONObject jsonResponse = new JSONObject();
JSONObject jsonExpirationDates = new JSONObject();
JSONArray jsonDate = new JSONArray();
JSONObject json = new JSONObject(response.getBody());
jsonResponse = json.getJSONObject(GET_RESPONSE);
jsonExpirationDates = jsonResponse.getJSONObject(GET_EXPIRATION_DATES);
jsonDate = jsonExpirationDates.getJSONArray(GET_DATE);
for(int i = 0; i < jsonDate.length(); i++){
String curDate = jsonDate.getString(i);
ret.add(curDate);
}
try {
ArrayList<Calendar> calList = parseCalendarDates(ret);
} catch (ParseException e) {
e.printStackTrace();
}
return ret;
}
示例12: doInBackground
import com.github.scribejava.core.model.Response; //导入依赖的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;
}
示例13: parseJSON
import com.github.scribejava.core.model.Response; //导入依赖的package包/类
public double parseJSON(Response response) throws JSONException{
ArrayList<Double> ret = new ArrayList<Double>();
double retDouble = 0.0;
JSONObject jsonResponse = new JSONObject();
JSONObject jsonPrices = new JSONObject();
JSONArray jsonPrice = new JSONArray();
JSONObject json = new JSONObject(response.getBody());
jsonResponse = json.getJSONObject(GET_RESPONSE);
jsonPrices = jsonResponse.getJSONObject(GET_PRICES);
jsonPrice = jsonPrices.getJSONArray(GET_PRICE);
for(int i = 0; i < jsonPrice.length(); i++){
String curPrice = jsonPrice.getString(i);
ret.add(Double.parseDouble(curPrice));
}
//pass the list we just parsed from TK to narrow down to one strike.
retDouble = getCurrentStrikePrice(ret);
return retDouble;
}
示例14: doInBackground
import com.github.scribejava.core.model.Response; //导入依赖的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;
}
示例15: parseJSON
import com.github.scribejava.core.model.Response; //导入依赖的package包/类
protected OptionOrder parseJSON(Response response) throws JSONException{
OptionOrder order = new OptionOrder();
JSONObject jsonResponse = new JSONObject();
JSONObject jsonWarning = new JSONObject();
JSONObject json = new JSONObject(response.getBody());
jsonResponse = json.getJSONObject(GET_RESPONSE);
jsonWarning = jsonResponse.getJSONObject(GET_WARNING);
if(jsonResponse.has("warning")){
order.setException("warningtext");
order.setIsException(true);
}else {
order.setClientOrderID(jsonResponse.getString("clientorderid"));
order.setOrderStatus(jsonResponse.getInt("orderstatus"));
order.setIsException(false);
}
return order;
}