use of oauth.signpost.exception.OAuthExpectationFailedException in project data-transfer-project by google.
the class SmugMugPhotoService method postRequest.
private <T> T postRequest(String url, HttpContent content, Map<String, String> headers, TypeReference<T> typeReference) throws IOException {
HttpRequestFactory requestFactory = httpTransport.createRequestFactory();
String fullUrl = url;
if (!fullUrl.contains("://")) {
fullUrl = BASE_URL + url;
}
HttpRequest postRequest = requestFactory.buildPostRequest(new GenericUrl(fullUrl), content);
HttpHeaders httpHeaders = new HttpHeaders().setAccept("application/json").setContentType("application/json");
for (Entry<String, String> entry : headers.entrySet()) {
httpHeaders.put(entry.getKey(), entry.getValue());
}
postRequest.setHeaders(httpHeaders);
try {
postRequest = (HttpRequest) this.authConsumer.sign(postRequest).unwrap();
} catch (OAuthMessageSignerException | OAuthExpectationFailedException | OAuthCommunicationException e) {
throw new IOException("Couldn't create post request", e);
}
HttpResponse response;
try {
response = postRequest.execute();
} catch (HttpResponseException e) {
throw new IOException("Problem making request: " + postRequest.getUrl(), e);
}
int statusCode = response.getStatusCode();
if (statusCode < 200 || statusCode >= 300) {
throw new IOException("Bad status code: " + statusCode + " error: " + response.getStatusMessage());
}
String result = CharStreams.toString(new InputStreamReader(response.getContent(), Charsets.UTF_8));
return MAPPER.readValue(result, typeReference);
}
use of oauth.signpost.exception.OAuthExpectationFailedException in project data-transfer-project by google.
the class SmugMugPhotoService method makeRequest.
private <T> SmugMugResponse<T> makeRequest(String url, TypeReference<SmugMugResponse<T>> typeReference) throws IOException {
HttpRequestFactory requestFactory = httpTransport.createRequestFactory();
String signedRequest;
try {
signedRequest = this.authConsumer.sign(BASE_URL + url + "?_accept=application%2Fjson");
} catch (OAuthMessageSignerException | OAuthExpectationFailedException | OAuthCommunicationException e) {
throw new IOException("Couldn't get albums", e);
}
HttpRequest getRequest = requestFactory.buildGetRequest(new GenericUrl(signedRequest));
HttpResponse response = getRequest.execute();
int statusCode = response.getStatusCode();
if (statusCode != 200) {
throw new IOException("Bad status code: " + statusCode + " error: " + response.getStatusMessage());
}
String result = CharStreams.toString(new InputStreamReader(response.getContent(), Charsets.UTF_8));
return MAPPER.readValue(result, typeReference);
}
use of oauth.signpost.exception.OAuthExpectationFailedException in project twitterdroid by fbrunel.
the class ConfigActivity method onCreate.
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
try {
String authURL = provider.retrieveRequestToken(consumer, CALLBACK_URL);
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(authURL)));
} catch (OAuthMessageSignerException e) {
e.printStackTrace();
} catch (OAuthNotAuthorizedException e) {
e.printStackTrace();
} catch (OAuthExpectationFailedException e) {
e.printStackTrace();
} catch (OAuthCommunicationException e) {
e.printStackTrace();
}
finish();
}
use of oauth.signpost.exception.OAuthExpectationFailedException in project data-transfer-project by google.
the class SmugMugAuth method generateAuthData.
@Override
public AuthData generateAuthData(IOInterface ioInterface) throws IOException {
// As per details: https://api.smugmug.com/api/v2/doc/tutorial/authorization.html
// and example:
// http://stackoverflow.com/questions/15194182/examples-for-oauth1-using-google-api-java-oauth
// Google library puts signature in header and not in request, see https://oauth.net/1/
OAuthConsumer consumer = new GoogleOAuthConsumer(appCredentials.key(), appCredentials.secret());
String permissions = (serviceMode == ServiceMode.EXPORT) ? "Read" : "Add";
OAuthProvider provider = new DefaultOAuthProvider("https://secure.smugmug.com/services/oauth/1.0a/getRequestToken", "https://secure.smugmug.com/services/oauth/1.0a/getAccessToken", "https://secure.smugmug.com/services/oauth/1.0a/authorize?Access=Full&Permissions=" + permissions);
String authUrl;
try {
authUrl = provider.retrieveRequestToken(consumer, OAuth.OUT_OF_BAND);
} catch (OAuthMessageSignerException | OAuthNotAuthorizedException | OAuthExpectationFailedException | OAuthCommunicationException e) {
throw new IOException("Couldn't generate authUrl", e);
}
String code = ioInterface.ask("Please visit: " + authUrl + " and enter code:");
try {
provider.retrieveAccessToken(consumer, code.trim());
} catch (OAuthMessageSignerException | OAuthNotAuthorizedException | OAuthExpectationFailedException | OAuthCommunicationException e) {
throw new IOException("Couldn't authorize", e);
}
return TokenSecretAuthData.create(consumer.getToken(), consumer.getTokenSecret());
}
use of oauth.signpost.exception.OAuthExpectationFailedException in project twitterdroid by fbrunel.
the class TwitterConnection method makeAuthConnection.
private HttpURLConnection makeAuthConnection(String resource) throws IOException {
HttpURLConnection conn = makeConnection(resource);
conn.setUseCaches(false);
try {
consumer.sign(conn);
} catch (OAuthMessageSignerException e) {
e.printStackTrace();
} catch (OAuthExpectationFailedException e) {
e.printStackTrace();
} catch (OAuthCommunicationException e) {
e.printStackTrace();
}
return conn;
}
Aggregations