use of org.scribe.model.Response in project fitscales by paulburton.
the class FitBitSyncService method postOAuth.
@Override
protected void postOAuth() {
try {
OAuthRequest request = new OAuthRequest(Verb.GET, API_BASE + "/user/-/profile.json");
oaService.signRequest(oaToken, request);
Response response = request.send();
if (DEBUG)
Log.d(TAG, "Profile response code " + response.getCode());
String body = response.getBody();
if (DEBUG)
Log.d(TAG, "Got profile body " + body);
JSONObject json = new JSONObject(body);
user = json.getJSONObject("user").getString("displayName");
} catch (Exception ex) {
if (DEBUG)
Log.e(TAG, "Failed to get profile", ex);
user = "unknown";
}
}
use of org.scribe.model.Response in project fitscales by paulburton.
the class RunKeeperSyncService method syncWeight.
@Override
public boolean syncWeight(float weight) {
try {
SimpleDateFormat tsFormat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss", Locale.ENGLISH);
String timestamp = tsFormat.format(new Date());
String json = String.format("{\"weight\": %.2f,\"timestamp\": \"%s\" }", weight, timestamp);
if (DEBUG)
Log.d(TAG, "Posting weight " + json);
OAuthRequest request = new OAuthRequest(Verb.POST, API_BASE + "/weight");
request.addPayload(json);
request.addHeader("Content-Type", "application/vnd.com.runkeeper.NewWeight+json");
oaService.signRequest(oaToken, request);
Response response = request.send();
int code = response.getCode();
if (DEBUG)
Log.d(TAG, "Response code " + code);
if (code == 200 || code == 201 || code == 204)
return true;
return false;
} catch (Exception ex) {
return false;
}
}
use of org.scribe.model.Response in project sling by apache.
the class XingOauthAuthenticationHandler method fetchUser.
protected XingUser fetchUser(final Token accessToken) throws Exception {
final OAuthRequest request = new OAuthRequest(Verb.GET, usersMeUrl);
oAuthService.signRequest(accessToken, request);
final Response response = request.send();
final Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
final Users users = gson.fromJson(response.getBody(), Users.class);
return users.getUsers().get(0);
}
use of org.scribe.model.Response in project OpenOLAT by OpenOLAT.
the class FacebookProvider method getUser.
@Override
public OAuthUser getUser(OAuthService service, Token accessToken) {
OAuthRequest request = new OAuthRequest(Verb.GET, "https://graph.facebook.com/me");
service.signRequest(accessToken, request);
Response oauthResponse = request.send();
String body = oauthResponse.getBody();
return parseInfos(body);
}
use of org.scribe.model.Response in project muikku by otavanopisto.
the class PyramusApi20ServiceImpl method getAccessToken.
@Override
public Token getAccessToken(Token requestToken, Verifier verifier) {
OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
request.addBodyParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
request.addBodyParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
request.addBodyParameter(OAuthConstants.CODE, verifier.getValue());
request.addBodyParameter(OAuthConstants.REDIRECT_URI, config.getCallback());
request.addBodyParameter("grant_type", "authorization_code");
if (config.hasScope())
request.addBodyParameter(OAuthConstants.SCOPE, config.getScope());
Response response = request.send();
ObjectMapper objectMapper = new ObjectMapper();
String tokenJson;
try {
tokenJson = objectMapper.writeValueAsString(objectMapper.readTree(response.getBody()));
} catch (IOException e) {
throw new OAuthException("Invalid Token JSON", e);
}
return api.getAccessTokenExtractor().extract(tokenJson);
}
Aggregations