当前位置: 首页>>代码示例>>Java>>正文


Java OAuthRequest.send方法代码示例

本文整理汇总了Java中com.github.scribejava.core.model.OAuthRequest.send方法的典型用法代码示例。如果您正苦于以下问题:Java OAuthRequest.send方法的具体用法?Java OAuthRequest.send怎么用?Java OAuthRequest.send使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.github.scribejava.core.model.OAuthRequest的用法示例。


在下文中一共展示了OAuthRequest.send方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import com.github.scribejava.core.model.OAuthRequest; //导入方法依赖的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());
}
 
开发者ID:tomrom95,项目名称:GameAuthoringEnvironment,代码行数:21,代码来源:TestAppLogin.java

示例2: sendRequestForData

import com.github.scribejava.core.model.OAuthRequest; //导入方法依赖的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;
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:24,代码来源:BaseOAuthClient.java

示例3: loadOAuthProviderAccount

import com.github.scribejava.core.model.OAuthRequest; //导入方法依赖的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;
}
 
开发者ID:rmap-project,项目名称:rmap,代码行数:23,代码来源:TwitterOAuthProvider.java

示例4: doInBackground

import com.github.scribejava.core.model.OAuthRequest; //导入方法依赖的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;
}
 
开发者ID:mikemey01,项目名称:Markets,代码行数:26,代码来源:ParseAccountData.java

示例5: doInBackground

import com.github.scribejava.core.model.OAuthRequest; //导入方法依赖的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;
}
 
开发者ID:mikemey01,项目名称:Markets,代码行数:27,代码来源:ParseStockQuote.java

示例6: doInBackground

import com.github.scribejava.core.model.OAuthRequest; //导入方法依赖的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;
}
 
开发者ID:mikemey01,项目名称:Markets,代码行数:24,代码来源:ParseOptionStrikePrice.java

示例7: doInBackground

import com.github.scribejava.core.model.OAuthRequest; //导入方法依赖的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;
}
 
开发者ID:mikemey01,项目名称:Markets,代码行数:27,代码来源:ParseOptionOrder.java

示例8: doInBackground

import com.github.scribejava.core.model.OAuthRequest; //导入方法依赖的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;
}
 
开发者ID:mikemey01,项目名称:Markets,代码行数:26,代码来源:ParseOptionOrderPreview.java

示例9: getSingleUseToken

import com.github.scribejava.core.model.OAuthRequest; //导入方法依赖的package包/类
public String getSingleUseToken() {
    OAuth10aService service = JamAuthConfig.instance().getOAuth10aService();
    final OAuthRequest request = new OAuthRequest(Verb.POST,
            JamAuthConfig.instance().getServerUrl() + "/v1/single_use_tokens",
            service);
    service.signRequest(JamAuthConfig.instance().getOAuth10aAccessToken(), request);

    final Response response = request.send();
    String body = response.getBody();

    Matcher matcher = SINGLE_USE_TOKEN_PATTERN.matcher(body);
    if (matcher.find()) {
        return matcher.group(0);
    }
    return null;
}
 
开发者ID:SAP,项目名称:SAPJamSampleCode,代码行数:17,代码来源:JamAuthConfig.java

示例10: retrieveUserProfileFromToken

import com.github.scribejava.core.model.OAuthRequest; //导入方法依赖的package包/类
@Override
protected FacebookProfile retrieveUserProfileFromToken(final OAuth2AccessToken accessToken) throws HttpAction {
    String body = sendRequestForData(accessToken, getProfileUrl(accessToken));
    if (body == null) {
        throw new HttpCommunicationException("Not data found for accessToken: " + accessToken);
    }
    final FacebookProfile profile = extractUserProfile(body);
    addAccessTokenToProfile(profile, accessToken);
    if (profile != null && this.requiresExtendedToken) {
        String url = CommonHelper.addParameter(EXCHANGE_TOKEN_URL, OAuthConstants.CLIENT_ID, getKey());
        url = CommonHelper.addParameter(url, OAuthConstants.CLIENT_SECRET, getSecret());
        url = addExchangeToken(url, accessToken);
        final OAuthRequest request = createOAuthRequest(url);
        final long t0 = System.currentTimeMillis();
        final Response response = request.send();
        final int code = response.getCode();
        body = response.getBody();
        final long t1 = System.currentTimeMillis();
        logger.debug("Request took: " + (t1 - t0) + " ms for: " + url);
        logger.debug("response code: {} / response body: {}", code, body);
        if (code == 200) {
            logger.debug("Retrieve extended token from  {}", body);
            final OAuth2AccessToken extendedAccessToken = ((DefaultApi20) getApi()).getAccessTokenExtractor().extract(body);
            logger.debug("Extended token: {}", extendedAccessToken);
            addAccessTokenToProfile(profile, extendedAccessToken);
        } else {
            logger.error("Cannot get extended token: {} / {}", code, body);
        }
    }
    return profile;
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:32,代码来源:FacebookClient.java

示例11: loadOAuthProviderAccount

import com.github.scribejava.core.model.OAuthRequest; //导入方法依赖的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);
	Response oauthResponse = oauthRequest.send();
	String jsonString = oauthResponse.getBody();
	JSONObject root = new JSONObject(jsonString);
	JSONArray emailArray = root.getJSONArray(GOOGLE_JSON_EMAILLIST_PROPERTY);
	JSONObject firstEmail = emailArray.getJSONObject(0);

	String accountId = root.getString(GOOGLE_JSON_ACCOUNTID_PROPERTY); 
	String displayName = root.getString(GOOGLE_JSON_DISPLAYNAME_PROPERTY);
	String publicId = firstEmail.getString(GOOGLE_JSON_EMAIL_PROPERTY); 
	String profilePath="";
	if (root.has(GOOGLE_JSON_PROFILEPATH_PROPERTY)){
		profilePath = root.getString(GOOGLE_JSON_PROFILEPATH_PROPERTY); 
	}
	
	OAuthProviderAccount profile = 
			new OAuthProviderAccount(accessToken, provider, displayName, accountId, publicId , profilePath);
		
	return profile;
}
 
开发者ID:rmap-project,项目名称:rmap,代码行数:28,代码来源:GoogleOAuthProvider.java

示例12: doInBackground

import com.github.scribejava.core.model.OAuthRequest; //导入方法依赖的package包/类
protected MarketDay doInBackground(Void... arg0){

        //not sure if this is right if the assignment below will happen correctly.
        MarketDay marketDay = new MarketDay();

        //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.getMarketYesterdaysMinuteData(symbol), service);
        service.signRequest(accessToken, request);
        Response response = request.send();

        //try parsing the JSON data.
        try {
            marketDay = parseJSON(response);
        } catch (JSONException e) {
            e.printStackTrace();
            marketDay.setError(e.toString());
        }

        return marketDay;
    }
 
开发者ID:mikemey01,项目名称:Markets,代码行数:28,代码来源:ParseData.java

示例13: doInBackground

import com.github.scribejava.core.model.OAuthRequest; //导入方法依赖的package包/类
protected OpenOptionPosition doInBackground(Void... voids){
    //sleep for a second for rate limiting.
    SystemClock.sleep(1000);

    OpenOptionPosition openOptionPosition = new OpenOptionPosition();

    //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.getOpenOptionPositions(), service);
    service.signRequest(accessToken, request);
    Response response = request.send();

    try {
        openOptionPosition = parseJSON(response);
    } catch (JSONException e) {
        e.printStackTrace();
        openOptionPosition.setError(e.toString());
    }

    return openOptionPosition;
}
 
开发者ID:mikemey01,项目名称:Markets,代码行数:28,代码来源:ParseOpenPosition.java

示例14: callback

import com.github.scribejava.core.model.OAuthRequest; //导入方法依赖的package包/类
@Override
public void callback(CallbackContext context) {
  context.verifyCsrfState();

  HttpServletRequest request = context.getRequest();
  OAuth20Service scribe = prepareScribe(context).build(GoogleApi20.instance());
  String oAuthVerifier = request.getParameter("code");
  OAuth2AccessToken accessToken = scribe.getAccessToken(new Verifier(oAuthVerifier));

  OAuthRequest userRequest = new OAuthRequest(Verb.GET, "https://www.googleapis.com/oauth2/v2/userinfo", scribe);
  scribe.signRequest(accessToken, userRequest);

  com.github.scribejava.core.model.Response userResponse = userRequest.send();
  if (!userResponse.isSuccessful()) {
    throw new IllegalStateException(format("Fail to authenticate the user. Error code is %s, Body of the response is %s",
      userResponse.getCode(), userResponse.getBody()));
  }
  String userResponseBody = userResponse.getBody();
  LOGGER.trace("User response received : %s", userResponseBody);
  GsonUser gsonUser = GsonUser.parse(userResponseBody);

  UserIdentity userIdentity = UserIdentity.builder()
    .setProviderLogin(gsonUser.getEmail())
    .setLogin(gsonUser.getEmail())
    .setName(gsonUser.getName())
    .setEmail(gsonUser.getEmail())
    .build();
  context.authenticate(userIdentity);
  context.redirectToRequestedPage();
}
 
开发者ID:steven-turner,项目名称:sonar-auth-google,代码行数:31,代码来源:GoogleIdentityProvider.java

示例15: getOpenId

import com.github.scribejava.core.model.OAuthRequest; //导入方法依赖的package包/类
public String getOpenId(OAuth2AccessToken accessToken, OAuth20Service service) {
    final OAuthRequest request = new OAuthRequest(Verb.GET, GET_OPEN_ID_URL, service);
    service.signRequest(accessToken, request);
    Response response = request.send();
    String rawResponse = null;
    try {
        rawResponse = response.getBody();
    } catch (IOException e) {

    }
    String formattedStr = rawResponse.substring(rawResponse.indexOf("{"), rawResponse.indexOf("}") + 1);
    return JsonUtil.getString("openid", formattedStr);
}
 
开发者ID:perrywang,项目名称:OAuthGateway,代码行数:14,代码来源:QQService.java


注:本文中的com.github.scribejava.core.model.OAuthRequest.send方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。