Si j'inclus le paramètre "Include_email=true", j'obtiens une erreur "Could not authenticate you".
Voici le code. S'il vous plaît, aidez-nous.
public final static String VERIFY_CREDENTIALS_URL ="https://api.twitter.com/1.1/account/verify_credentials.json";
public final static String AUTHORIZATION_VERIFY_CREDENTIALS = "OAuth " +
"oauth_consumer_key=\"{key}\", " +
"oauth_signature_method=\"" + SIGNATURE_METHOD + "\", " +
"oauth_timestamp=\"{ts}\", " +
"oauth_nonce=\"{nonce}\", " +
"oauth_version=\"1.0\", " +
"oauth_signature=\"{signature}\", " +
"oauth_token=\"{token}\"";
public static TwitterVerifyCredentials getVerifyCredentials(String appKey, String appSecret, TwitterAccessToken accessToken) throws GeneralSecurityException, IOException {
String ts = "" + TimeUtility.now().getTime()/1000;
String oauth_nonce = UUID.randomUUID().toString().replaceAll("-", "");
String parameters = "oauth_consumer_key=" + appKey + "&oauth_nonce=" + oauth_nonce + "&oauth_signature_method=" + SIGNATURE_METHOD + "&oauth_timestamp=" + ts + "&oauth_token=" + encode(accessToken.getToken()) + "&oauth_version=1.0";
String signature = "GET&" + encode(VERIFY_CREDENTIALS_URL) + "&" + encode(parameters);
System.out.println(signature);
String result = TwitterOAuth.AUTHORIZATION_VERIFY_CREDENTIALS;
result = StringUtils.replace(result, "{nonce}", oauth_nonce);
result = StringUtils.replace(result, "{ts}", "" + ts);
result = StringUtils.replace(result, "{key}", appKey);
result = StringUtils.replace(result, "{signature}", encode(computeSignature(signature, appSecret + "&" + encode(accessToken.getTokenSecret()))));
result = StringUtils.replace(result, "{token}", encode(accessToken.getToken()));
HashMap<String, String> headers = new HashMap<>();
headers.put("Authorization", result);
String s = SiteFunctions.urlGet(VERIFY_CREDENTIALS_URL+"?include_email=true", headers);
System.out.println(s);
return new TwitterVerifyCredentials(); // while testing
}
Si je supprime "?include_email=true", tout va bien !