Reputation: 4256
I am trying to build a tumblr client in android but am running into response code 403 - Forbidden.
The api docs suggest i use email and password parameters to validate credentials and get account information. I have tried out the following code but as specified get a 403 response code. can anyone suggest what i m doing wrong.
String url = "http://www.tumblr.com/api/authenticate";
HttpParams params = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(params, 20000);
HttpConnectionParams.setSoTimeout(params, 20000);
DefaultHttpClient httpclient = new DefaultHttpClient(params);
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(_username + ":" + _password);
httpclient.getCredentialsProvider().setCredentials(new AuthScope(null,-123),credentials);
HttpPost method = new HttpPost(url);
HttpResponse response = httpclient.execute(method);
response.getStatusLine().toString(); // this gives me a 403 res code (Forbidden)..
Upvotes: 0
Views: 1085
Reputation: 2802
Here's what i use in my app to authenticate:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(
"http://www.tumblr.com/api/authenticate");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("email", Username));
nameValuePairs.add(new BasicNameValuePair("password", Password));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
if (response.getStatusLine().getStatusCode() != 200) {
return false;
}
return true;
}
Upvotes: 3