Skip to content

Instantly share code, notes, and snippets.

@PyYoshi
Created February 28, 2014 04:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PyYoshi/9265191 to your computer and use it in GitHub Desktop.
Save PyYoshi/9265191 to your computer and use it in GitHub Desktop.
Volley+oauth-signpostでOAuthリクエスト ref: http://qiita.com/PyYoshi@github/items/fe4b0a72e98852724859
RequestQueue requestQueue = Volley.newRequestQueue(context, new OAuthHurlStack(consumer)) // consumerはOAuthConsumer
public class OAuthHttpClientStack extends HttpClientStack {
private final OAuthConsumer consumer;
public OAuthHttpClientStack(HttpClient client, OAuthConsumer consumer) {
super(client);
this.consumer = consumer;
}
@Override
protected void onPrepareRequest(HttpUriRequest request) throws IOException {
super.onPrepareRequest(request);
try {
this.consumer.sign(request);
} catch (OAuthMessageSignerException e) {
// TODO: OAuthMessageSignerExceptionハンドリングを実装
e.printStackTrace();
} catch (OAuthExpectationFailedException e) {
// TODO: OAuthExpectationFailedExceptionハンドリングを実装
e.printStackTrace();
} catch (OAuthCommunicationException e) {
// TODO: OAuthCommunicationExceptionハンドリングを実装
e.printStackTrace();
}
}
}
public class OAuthHurlStack extends HurlStack {
private final OAuthConsumer consumer;
public OAuthHurlStack(OAuthConsumer consumer) {
this.consumer = consumer;
}
@Override
protected HttpURLConnection createConnection(URL url) throws IOException {
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
try {
this.consumer.sign(connection);
} catch (OAuthMessageSignerException e) {
// TODO: OAuthMessageSignerExceptionハンドリングを実装
e.printStackTrace();
} catch (OAuthExpectationFailedException e) {
// TODO: OAuthExpectationFailedExceptionハンドリングを実装
e.printStackTrace();
} catch (OAuthCommunicationException e) {
// TODO: OAuthCommunicationExceptionハンドリングを実装
e.printStackTrace();
}
return connection;
}
}
@pawarlalit29
Copy link

how can i pass the token to header using this volley example

@rio45ka
Copy link

rio45ka commented Jun 14, 2015

Can you give example complete for use this?
Thanx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment