我的任务是创建可以从x帐户获取最新推文的应用。 这是我的代码,我所做的。但是,只有当我设置(作为搜索字符串)我的帐户名时,才会得到结果(大于0)。否则我一无所获。有人能解释我为什么吗?我会感谢任何帮助。
private ListView lv;
private EditText et;
private ArrayAdapter<String> adapter;
String[] values;
private Token token = null;
private Credential c = null;
private UserAccountManager m = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv = (ListView) findViewById(R.id.listView1);
et = (EditText) findViewById(R.id.editText1);
et.setText("twapime");
doRest();// first run, initialization, first search
}
private void doRest() {
initAccount();
initSearching();
}
private void initSearching() {
ArrayList<String> listax = getSearchResults(et.getText().toString());
initListViewAdapter(listax);
}
private void initListViewAdapter(ArrayList<String> listax) {
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, listax);
lv.setAdapter(adapter);
}
private void initAccount() {
token = new Token("xxxx",
"xxxx");
c = new Credential("xxxx",
"xxxx", token);
m = UserAccountManager.getInstance(c);
}
private ArrayList<String> getSearchResults(String userTwitter) {
ArrayList<String> lista = new ArrayList<String>();
try {
if (m.verifyCredential()) {
SearchDevice sd = SearchDevice.getInstance();
Query q1 = QueryComposer.from(userTwitter);
Tweet[] ts = sd.searchTweets(q1);
System.out.println(ts.length);
for (int i = 0; i < ts.length; i++) {
lista.add(ts[i].getString(MetadataSet.TWEET_CONTENT));
}
}
} catch (IOException e) {
e.printStackTrace();
} catch (LimitExceededException e) {
e.printStackTrace();
}
return lista;
}
public void btnSearcher(View w) {//OnClickListener
initSearching();
}
答案 0 :(得分:0)
我认为当有人阻止不信任用户的公共信息数据时会发生这种情况。