开发者

Jesey Oauth client and "%20" spaces

开发者 https://www.devze.com 2022-12-18 05:43 出处:网络
HI all.I am trying to use the Sun Jersey Client API with Jesey Oauth to connect to twitter.Lets say I already have the oauth token and token secret.

HI all. I am trying to use the Sun Jersey Client API with Jesey Oauth to connect to twitter. Lets say I already have the oauth token and token secret.

String accessToken = MY_TOKEN;
String accessTokenSecret = MY_TOKEN_SECRET;
String url = "http://twitter.com/statuses/update.xml";

// initialize the params and secret.
OAuthParameters params = initOAuthParams();
params.token(accessToken);
OAuthSecrets secrets = initOAuthSecrets();
secrets.tokenSecret(accessTokenSecret);

// now access the resource
OAuthClientFilter filter = getClientFilter(params, secrets);
WebResource resource = client.resource(url);
resource.addFilter(filter);

MultivaluedMapImpl form = new MultivaluedMapImpl();
String status = new String("test with spaces");
form.add("status", status);

// post it
resource.type("application/x-www-form-urlencoded").post(String.class, form);

This code will work, but the spaces are encoded as "+". That would normally be fine, but Twitter seems to only take "%20". if I try replacing the post with

resource.type("application/x-www-form-urlencoded").post(String.class, "status=test with spaces");

or

resource.type("application/x-www-form-urlencoded").post(String.class, "status=test%20with%20spaces");

twitter will respond with a 401, Incorrect Signature. If I try just

resource.type("application/x-www-form-urlencoded").post(String.class, "status=test");

twitter will accept it. How can I get Oauth to work with spaces en开发者_如何转开发coded as "%20"?

Thanks! Mason


This should be fixed in jersey 1.3 https://jersey.dev.java.net/issues/show_bug.cgi?id=511 https://jersey.dev.java.net/issues/show_bug.cgi?id=433

but we are running into the same problem.

A simple net.oauth.client.OAuthClient does the job

0

精彩评论

暂无评论...
验证码 换一张
取 消