推特。Verify_credentials。OAuth API。错误“无法验证您的身份。” Include_email = true

java api twitter oauth

475 观看

1回复

133 作者的声誉

如果我包含参数“ 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
    }

如果我删除“?include_email = true”,一切都可以!

作者: Jenkamen 的来源 发布者: 2017 年 9 月 15 日

回应 1


1

26 作者的声誉

决定

VERIFY_CREDENTIALS_URL在您的程序中应添加?include_email=true。如果您想从Twitter OAuth api获取电子邮件,则签名中的网址应为?include_email=true

作者: Richard.Sun 发布者: 2018 年 3 月 8 日
32x32