推特。 Verify_credentials。 OAuth Api。错误"无法验证您。" Include_email =真

时间:2017-09-15 05:26:09

标签: java api twitter oauth

如果我包含参数" Include_email = true"我收到错误"无法验证您。"

这里的代码。请帮忙。

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
    }

如果我删除&#34;?include_email = true&#34; everythink没关系!

1 个答案:

答案 0 :(得分:1)

程序中的

VERIFY_CREDENTIALS_URL应添加?include_email=true。如果您想从Twitter OAuth api收到电子邮件,签名中的网址应为?include_email=true