Jersey verify_credentials error when using include_email

oauth
api

#1

I’m using JAX-RS Client for my server to make API calls to Twitter. I can request account/verify_credentials and it returns the info. But if I put the “?include_email=true” parameter, I always get an error (Could not authenticate you).
The request works fine on curl or postman, but it won’t work on javax Client


#2

Can you share any further code? I wonder whether the Java client is not encoding the parameter correctly as part of the OAuth dance.


#3

Sorry for being late…Here’s the code:

import javax.ws.rs.client.Client;    
import javax.ws.rs.core.Response;
import javax.ws.rs.client.WebTarget;

WebTarget webResource = client.target(apiUrl);
    	Response clientResponse = webResource
    			.queryParam("include_email", "true")
    			.request()
    			.header("Authorization",authHeader)
    			.get();

apiUrl = https://api.twitter.com/1.1/account/verify_credentials.json

If i remove the .queryParam("include_email", true) line, the code works fine. Thanks!


#4

Are you able to do any tracing to see whether .queryParam("include_email", true) is indeed being passed as a ? style query parameter on the URL? It has been a really long time since I did any coding with javax.ws.*!


#5

The include_email is passed in the GET request. I’ve also tried to target https://api.twitter.com/1.1/account/verify_credentials.json?include_email=true as the API url, but still the same error.

Don’t know if this helps, but I’ve tried a different call for client:

return client.target( apiUrl )
		.queryParam("include_email", true)
		.request()
		.header("Authorization", authHeader)
		.get( Map.class );

and this time it gives HTTP 401 Authorization required error, although the Authorization header is correct.


#6

Can you try changing the value of include_email from a boolean to a string?


#7

I’ve tried that, but still doesn’t work


#8

How are you generating authHeader? Are you making sure that the include_email parameter is getting included in the signature base values?


#9

Well, I didn’t put the include_email in the signature parameters so that might be it. But without the email parameter, the authHeader is good, I can make requests with it. I’ll add the change to the signature monday and see if it’s solved, thanks

EDIT: You were right, I didn’t include the email parameter when generating the signature. but it works now. Thanks !


#10