How to use google-oauth-java-client

I want to use google-oauth-java-client to get authorization code from sina weibo

this is a GET method that gets code from sina

https://api.weibo.com/oauth2/authorize?client_id=70090552&response_type=code&redirect_uri=http://127.0.0.1/weibo 

Please allow this without a web page, only a client !

Can someone give me some advice?

+4
source share
3 answers

I'm sorry that I'm wrong! Get the method to use the browser and return the code The Post method uses the HttpRequest, and we can get the parameter from HtppResponse

So, if you want to get the code, just use a browser and redirect the URL to get the code

This is how I get access_token

If you want, you can use google-oauth-java-client to authorize twitter facebook

I solve this javadoc which shows me some examples This is the root of JavaDoc This is the package I use to solve Here is the example I am writing

 // https://server.example.com/token server url example try { TokenResponse response = new AuthorizationCodeTokenRequest(new NetHttpTransport(), new JacksonFactory(), new GenericUrl("here is the server url "), "here write your code") .setRedirectUri("here write the redirectUrl") .set("client_id","here write your client_id") .set("client_secret","here write your client_secret") .set("Other else need","Other else need") .execute(); System.out.println("Access token: " + response.getAccessToken()); } catch (TokenResponseException e) { if (e.getDetails() != null) { System.err.println("Error: " + e.getDetails().getError()); if (e.getDetails().getErrorDescription() != null) { System.err.println(e.getDetails().getErrorDescription()); } if (e.getDetails().getErrorUri() != null) { System.err.println(e.getDetails().getErrorUri()); } } else { System.err.println(e.getMessage()); } } 
+4
source

This and this will help you. First understand the mechanism and implement it according to your scenario.

+2
source

All Articles