Created
February 28, 2014 04:21
-
-
Save PyYoshi/9265191 to your computer and use it in GitHub Desktop.
Volley+oauth-signpostでOAuthリクエスト ref: http://qiita.com/PyYoshi@github/items/fe4b0a72e98852724859
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RequestQueue requestQueue = Volley.newRequestQueue(context, new OAuthHurlStack(consumer)) // consumerはOAuthConsumer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
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
how can i pass the token to header using this volley example