use of org.apache.http.message.BasicNameValuePair in project newsrob by marianokamp.
the class GRAnsweredBadRequestException method authenticate.
boolean authenticate(Context context, String email, String password, String captchaToken, String captchaAnswer) throws ClientProtocolException, IOException, AuthenticationFailedException {
getEntryManager().getNewsRobNotificationManager().cancelSyncProblemNotification();
NewsRobHttpClient httpClient = NewsRobHttpClient.newInstance(false, context);
try {
// ?client="
HttpPost authenticateRequest = new HttpPost("https://www.google.com/accounts/ClientLogin");
// +
// CLIENT_NAME);
List<NameValuePair> keyValuePairs = new ArrayList<NameValuePair>();
// HOSTED_OR_GOOGLE
keyValuePairs.add(new BasicNameValuePair("accountType", "GOOGLE"));
keyValuePairs.add(new BasicNameValuePair("Email", email));
keyValuePairs.add(new BasicNameValuePair("Passwd", password));
keyValuePairs.add(new BasicNameValuePair("source", CLIENT_NAME));
keyValuePairs.add(new BasicNameValuePair("service", "reader"));
if (captchaToken != null) {
keyValuePairs.add(new BasicNameValuePair("logintoken", captchaToken));
keyValuePairs.add(new BasicNameValuePair("logincaptcha", captchaAnswer));
}
authenticateRequest.setEntity(new UrlEncodedFormEntity(keyValuePairs, HTTP.UTF_8));
HttpResponse response = httpClient.execute(authenticateRequest);
int statusCode = response.getStatusLine().getStatusCode();
String content = EntityUtils.toString(response.getEntity());
switch(statusCode) {
case HttpStatus.SC_UNAUTHORIZED:
case HttpStatus.SC_FORBIDDEN:
Map<String, String> keyValues = U.parseKeyValuePairsFromString(content);
String error = keyValues.get("Error");
String requiredCaptchaToken = keyValues.get("CaptchaToken");
String captchaUrl = keyValues.get("CaptchaUrl");
if (captchaUrl != null) {
captchaUrl = "https://www.google.com/accounts/" + captchaUrl;
String msg = "Error=" + error + " CaptchaToken=" + captchaToken + " CaptchaUrl=" + captchaUrl;
Log.d(TAG, msg);
PL.log(msg, context);
throw new LoginWithCaptchaRequiredException(requiredCaptchaToken, captchaUrl);
}
if ("BadAuthentication".equals(error))
error = "Username / Password wrong?";
else
error += "\n" + response.getStatusLine();
throw new AuthenticationFailedException("Authentication failed:\n" + error);
case HttpStatus.SC_OK:
break;
default:
String msg = "Oh, status code was " + statusCode + " but unexpected.";
PL.log(msg, context);
Log.w(TAG, msg);
throw new AuthenticationFailedException("Autentication failed:\n" + EntityUtils.toString(response.getEntity()));
}
getEntryManager().saveAuthToken(new AuthToken(AuthToken.AuthType.AUTH_STANDALONE, U.parseKeyValuePairsFromString(content).get("Auth")));
response.getEntity().consumeContent();
getEntryManager().getNewsRobNotificationManager().cancelSyncProblemNotification();
return true;
} finally {
httpClient.close();
}
}
use of org.apache.http.message.BasicNameValuePair in project newsrob by marianokamp.
the class GRAnsweredBadRequestException method submitSubscribe.
public boolean submitSubscribe(String url2subscribe) throws ReaderAPIException {
Timing t = new Timing("Submit Subscribe", context);
NewsRobHttpClient httpClient = NewsRobHttpClient.newInstance(false, context);
try {
HttpPost editApiRequest = new HttpPost(getGoogleHost() + "/reader/api/0/subscription/edit");
// quickadd
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("client", CLIENT_NAME));
nameValuePairs.add(new BasicNameValuePair("ac", "subscribe"));
// quickadd
nameValuePairs.add(new BasicNameValuePair("s", "feed/" + url2subscribe));
HttpResponse resp = submitPostRequest(httpClient, editApiRequest, nameValuePairs, false);
return resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK;
} catch (Exception e) {
String message = "Problem during submission of subscribe: " + e.getMessage();
Log.e(TAG, message, e);
throw new ReaderAPIException(message, e);
} finally {
httpClient.close();
t.stop();
}
}
use of org.apache.http.message.BasicNameValuePair in project newsrob by marianokamp.
the class GRAnsweredBadRequestException method submitNotes.
public void submitNotes(Job job) throws ReaderAPIException {
Timing t = new Timing("Submit Notes", context);
List<Entry> entries = getEntryManager().getEntriesWithNotesToBeSubmitted();
if (entries.isEmpty()) {
t.stop();
return;
}
NewsRobHttpClient httpClient = NewsRobHttpClient.newInstance(false, context);
try {
for (Entry entry : entries) {
HttpPost editApiRequest = new HttpPost(getGoogleHost() + "/reader/api/0/item/edit?client=" + CLIENT_NAME);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("client", CLIENT_NAME));
nameValuePairs.add(new BasicNameValuePair("title", entry.getTitle()));
nameValuePairs.add(new BasicNameValuePair("url", entry.getAlternateHRef()));
String s = "This feed url can only be set after the next article from this feed is imported into NewsRob. You can force this with Clear Cache/Refresh.";
if (entry.getFeedAlternateUrl() != null)
s = entry.getFeedAlternateUrl();
nameValuePairs.add(new BasicNameValuePair("srcUrl", s));
nameValuePairs.add(new BasicNameValuePair("srcTitle", entry.getFeedTitle()));
nameValuePairs.add(new BasicNameValuePair("snippet", entry.getContent()));
submitPostRequest(httpClient, editApiRequest, nameValuePairs, false);
getEntryManager().update(entry);
}
} catch (Exception e) {
String message = "Problem during submission of note: " + e.getMessage();
Log.e(TAG, message, e);
throw new ReaderAPIException(message, e);
} finally {
httpClient.close();
t.stop();
}
}
use of org.apache.http.message.BasicNameValuePair in project newsrob by marianokamp.
the class GRAnsweredBadRequestException method addParametersIncludingTokenToPostRequest.
private void addParametersIncludingTokenToPostRequest(HttpPost postRequest, List<NameValuePair> nameValuePairs) {
// add token to the parameters, encode them and put them in the post
// request
List<NameValuePair> nvps = new ArrayList<NameValuePair>(nameValuePairs.size() + 1);
nvps.addAll(nameValuePairs);
nvps.add(new BasicNameValuePair("T", token));
try {
postRequest.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
use of org.apache.http.message.BasicNameValuePair in project wechat by motianhuo.
the class LoginActivity method onClick.
@Override
public void onClick(View v) {
switch(v.getId()) {
case R.id.img_back:
Utils.finish(LoginActivity.this);
break;
case R.id.tv_wenti:
Utils.start_Activity(LoginActivity.this, WebViewActivity.class, new BasicNameValuePair(Constants.Title, "帮助"), new BasicNameValuePair(Constants.URL, "http://weixin.qq.com/"));
break;
case R.id.btn_qtlogin:
startActivity(new Intent(LoginActivity.this, RegisterActivity.class));
overridePendingTransition(R.anim.push_up_in, R.anim.push_up_out);
break;
case R.id.btn_login:
getLogin();
break;
default:
break;
}
}
Aggregations