Android 访问Identi.ca更新状态

Android 访问Identi.ca更新状态,android,Android,我正在使用Commonware的Android教程,无法理解为什么我会出错。这是我的密码: public class Patchy extends Activity { public String DEB_TAG = "Patchy.java"; private DefaultHttpClient client = null; private EditText user = null; private EditText password

我正在使用Commonware的Android教程,无法理解为什么我会出错。这是我的密码:

public class Patchy extends Activity {
public String DEB_TAG       = "Patchy.java";

private DefaultHttpClient client    = null;
private EditText user               = null;
private EditText password           = null;
private EditText status             = null;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Log.d(DEB_TAG, "inside oncreate");

    user        = (EditText)findViewById(R.id.user);
    password    = (EditText)findViewById(R.id.password);
    status      = (EditText)findViewById(R.id.status);

    Button send = (Button)findViewById(R.id.send);

    send.setOnClickListener(onSend);

    client = new DefaultHttpClient();
}

@Override
public void onDestroy() {
    super.onDestroy();
    client.getConnectionManager().shutdown();
}

private String getCredentials() {
    String u = user.getText().toString();
    String p = password.getText().toString();
    Log.d(DEB_TAG, "Value of u and p is " + u + "..." + p);
    String temp = Base64.encodeBytes((u+":"+p).getBytes());
    Log.d(DEB_TAG, "Value of temp is " + temp);
    return temp;
}

private void updateStatus() {
    try {
        String s = status.getText().toString();
        Log.d(DEB_TAG, "Value of status is " + s);

        HttpPost post = new HttpPost("https://identi.ca/api/statuses/update.json");

        post.addHeader("Authorization", "Basic" +getCredentials());

        List<NameValuePair> form = new ArrayList<NameValuePair>();

        form.add(new BasicNameValuePair("status", s));

        post.setEntity(new UrlEncodedFormEntity(form, HTTP.UTF_8));

        ResponseHandler<String> responseHandler = new BasicResponseHandler();

        String responseBody = client.execute(post, responseHandler);

        JSONObject response = new JSONObject(responseBody);

    }catch (Throwable t) {
        Log.e(DEB_TAG, "Exception in updateStatus()", t);
        goBlooey(t);
    }
}

private void goBlooey(Throwable t){
    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    builder
    .setTitle("Exception!")
    .setMessage(t.toString())
    .setPositiveButton("OK", null)
    .show();
}
private View.OnClickListener onSend = new View.OnClickListener() {

    @Override
    public void onClick(View v) {
        updateStatus();

    }
};
} 这是我的LogCat错误msgs:

08-11:52:34.769:ERROR/Patchy.java4738:updateStatus中的异常 08-11 11:52:34.769:ERROR/Patchy.java4738:org.apache.http.client.HttpResponseException:未经授权 08-11:52:34.769:ERROR/Patchy.java4738:org.apache.http.impl.client.BasicResponseHandler.HandlerResponseBasicResponseHandler.java:71 08-11:52:34.769:ERROR/Patchy.java4738:org.apache.http.impl.client.BasicResponseHandler.HandlerResponseBasicResponseHandler.java:59 08-11:52:34.769:ERROR/Patchy.java4738:org.apache.http.impl.client.AbstractHttpClient.ExecuteActHttpClient.java:657 08-11:52:34.769:ERROR/Patchy.java4738:org.apache.http.impl.client.AbstractHttpClient.ExecuteActHttpClient.java:627 08-11:52:34.769:ERROR/Patchy.java4738:org.apache.http.impl.client.AbstractHttpClient.ExecuteActHttpClient.java:616 08-11:52:34.769:ERROR/Patchy.java4738:at example.com.Patchy.Patchy.updateStatusPatchy.java:83 08-11:52:34.769:ERROR/Patchy.java4738:at example.com.Patchy.Patchy.access$0Patchy.java:66 08-11:52:34.769:ERROR/Patchy.java4738:at example.com.Patchy.Patchy$1.onClickPatchy.java:106 08-11:52:34.769:ERROR/Patchy.java4738:at-android.view.view.performClickView.java:2365 08-11 11:52:34.769:ERROR/Patchy.java4738:at-android.view.view.onTouchEventView.java:4180 08-11:52:34.769:ERROR/Patchy.java4738:at-android.widget.TextView.onTouchEventTextView.java:6696 08-11:52:34.769:ERROR/Patchy.java4738:at-android.view.view.dispatchTouchEventView.java:3710 08-11:52:34.769:ERROR/Patchy.java4738:at-android.view.ViewGroup.dispatchTouchEventViewGroup.java:885 08-11:52:34.769:ERROR/Patchy.java4738:at-android.view.ViewGroup.dispatchTouchEventViewGroup.java:885 08-11:52:34.769:ERROR/Patchy.java4738:at-android.view.ViewGroup.dispatchTouchEventViewGroup.java:885 08-11:52:34.769:ERROR/Patchy.java4738:at-android.view.ViewGroup.dispatchTouchEventViewGroup.java:885 08-11:52:34.769:ERROR/Patchy.java4738:com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEventPhoneWindow.java:1695 08-11 11:52:34.769:ERROR/Patchy.java4738:com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEventPhoneWindow.java:1111 08-11:52:34.769:ERROR/Patchy.java4738:at android.app.Activity.dispatchTouchEventActivity.java:2061 08-11:52:34.769:ERROR/Patchy.java4738:com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEventPhoneWindow.java:1679 08-11:52:34.769:ERROR/Patchy.java4738:at-android.view.ViewRoot.handleMessageViewRoot.java:1696 08-11:52:34.769:ERROR/Patchy.java4738:at android.os.Handler.dispatchMessageHandler.java:99 08-11:52:34.769:ERROR/Patchy.java4738:at android.os.Looper.loopLooper.java:130 08-11:52:34.769:ERROR/Patchy.java4738:at android.app.ActivityThread.mainActivityThread.java:4425 08-11:52:34.769:ERROR/Patchy.java4738:at java.lang.reflect.Method.invokenactive Method 08-11:52:34.769:ERROR/Patchy.java4738:at java.lang.reflect.Method.invokeMethod.java:521 08-11:52:34.769:ERROR/Patchy.java4738:com.android.internal.os.ZygoteInit$MethodAndArgsCaller.runZygoteInit.java:860 08-11 11:52:34.769:ERROR/Patchy.java4738:com.android.internal.os.ZygoteInit.mainZygoteInit.java:618 08-11:52:34.769:ERROR/Patchy.java4738:at dalvik.system.NativeStart.main本地方法

在我的手机上会弹出一个对话框,其中包含错误异常。org.apache.http.client.HttpResponseException:未经授权


有什么想法吗?

有关公共软件的问题,请访问。我差点错过了这个问题


确保您输入了正确的用户名和密码。此外,请确保您单击了从identi.ca获得的电子邮件中的链接,否则无法使用API。

您确定添加的凭据正确吗?因为此页面需要登录名和密码。请使用凭据和基本身份验证在httpclient上查看您的帖子。最好编写一个应用程序来测试httpclient。我正在输入正确的用户名和密码…通过日志语句进行双重检查,并使用相同的凭据从计算机进入站点。我可以从桌面通过Internet登录。