【问题标题】:How to display tweets from a twitter account and tweet that same account from an android app using twitter4j?如何显示来自 twitter 帐户的推文并使用 twitter4j 从 android 应用程序中推文相同的帐户?
【发布时间】:2014-03-25 04:28:32
【问题描述】:

我目前正在尝试制作一个应用程序,该应用程序应该从 Twitter 帐户(不是我的,而是第三方)中提取最后 10 或 20 条推文,并显示它们。我还希望能够让用户向此人发布推文并在推特上关注他们(如果他们还没有的话)。

过去几个小时我一直在看教程,真的无法理解它。我已经将 twitter4j-core-4.0.1.jar 导入到我的项目中。

在我的 MainActivity.java 中,我有一个响应按钮的方法:


public void twitter(View view) 
{
    //Create an intent and send it the twitter activity class
    Intent twitterActivity = new Intent(this, TwitterActivity.class);
    startActivity(twitterActivity);
}

所以我想知道的是,如何设置视图以显示来自 twitter 帐户的推文,以及允许用户发布推文和/或关注它们。

这是我目前在 TwitterActivity.java 中的内容:


import java.util.List;

import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.User;
import android.os.Bundle;

import android.app.Activity;

import android.support.v4.app.NavUtils;
import android.view.Menu;
import android.view.MenuItem;

public class TwitterActivity extends Activity 
{

// I think I need to create some global variables here for the consumer key and consumer secret.

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_twitter);

        setupActionBar();

        // I assume the twitter set up happens here.

    }

.....

}

【问题讨论】:

    标签: java android twitter


    【解决方案1】:

    我猜你必须使用 JSONObjectJSONArray 才能让它工作。

    使用此 uri 获取推文:

    http://api.tweeter.com/1/statuses/user_timeline.json?screen_name=

    也可以使用以下代码获取推文:

    new Read().execute("text")
    

    text 有实际的推文。

    然后您可以使用 StringBuilder 并将用户名附加到上面提到的 URI 中。

    【讨论】:

    • 第一篇文章不错!欢迎使用 Stack Overflow。
    猜你喜欢
    • 2021-09-20
    • 1970-01-01
    • 1970-01-01
    • 2011-09-18
    • 2020-04-16
    • 2018-10-02
    • 1970-01-01
    • 1970-01-01
    • 2012-07-24
    相关资源
    最近更新 更多