Alternative for getPublicTimeline for jtwitter

半世苍凉 提交于 2019-12-13 15:04:50

问题


Edit===========

Pasted from MANIFEST.MF file:

Main-Class: winterwell.jtwitter.Twitter
Implementation-Version: 2.9.0
Implementation-Title: JTwitter client library by Winterwell


Android Studio 0.2.9
jtwitter 2.9.0

Hello,

I have been following the marakana videos on creating a yamba client.

However, I have noticed that the getPublicTimeline api call has now been removed from the jtwitter as twitter no longer supports this. So I have tired to use an alternative instead but getting a error which I have cut and pasted below.

The different API I have tried is getFriendsTimeline, getHomeTimeline.

My code snippet I am using:

@Override
protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.status);

    edit_status = (EditText)findViewById(R.id.editText);
    tw = new Twitter("student", "password");
    tw.setAPIRootUrl("http://yamba.marakana.com/api");
}

public class GetHomeStatus extends AsyncTask<String, Integer, String>
{
    @Override
    protected String doInBackground(String... statues)
    {
        int i = 0;
        List<winterwell.jtwitter.Status> timeline;

        try {
            timeline = twitter.getFriendsTimeline();
            //twitter.setStatus("Hello, there!");
        }
        catch (TwitterException e) {
            e.printStackTrace();
            return "Failed to get timeline";
        }

I don't think there is a problem with the background thread, as twitter.setStatus("Hello, there!"); works fine.

Many suggestions would be most grateful

Exception:

 275-445/system_process W/InputMethodManagerService﹕ Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@4193edb0 attribute=null, token = android.os.BinderProxy@4177e720
09-11 03:58:37.108    3187-3204/com.sunsystems.yambaapp W/System.err﹕ winterwell.jtwitter.TwitterException: 301 Moved Permanently
09-11 03:58:37.108    3187-3204/com.sunsystems.yambaapp W/System.err﹕ HTTP/1.1 301 Moved Permanently https://marakana.com/s/tags/breaking_open/?include_entities=1& -> https://marakana.com/s/tags/breaking_open/?include_entities=1&
09-11 03:58:37.118    3187-3204/com.sunsystems.yambaapp W/System.err﹕ at winterwell.jtwitter.URLConnectionHttpClient.processError(URLConnectionHttpClient.java:513)
09-11 03:58:37.118    3187-3204/com.sunsystems.yambaapp W/System.err﹕ at winterwell.jtwitter.URLConnectionHttpClient.connect(URLConnectionHttpClient.java:155)
09-11 03:58:37.118    3187-3204/com.sunsystems.yambaapp W/System.err﹕ at winterwell.jtwitter.URLConnectionHttpClient.getPage2(URLConnectionHttpClient.java:311)
09-11 03:58:37.118    3187-3204/com.sunsystems.yambaapp W/System.err﹕ at winterwell.jtwitter.URLConnectionHttpClient.getPage(URLConnectionHttpClient.java:251)
09-11 03:58:37.118    3187-3204/com.sunsystems.yambaapp W/System.err﹕ at winterwell.jtwitter.Twitter.getStatuses(Twitter.java:1660)
09-11 03:58:37.118    3187-3204/com.sunsystems.yambaapp W/System.err﹕ at winterwell.jtwitter.Twitter.getHomeTimeline(Twitter.java:1162)
09-11 03:58:37.118    3187-3204/com.sunsystems.yambaapp W/System.err﹕ at winterwell.jtwitter.Twitter.getFriendsTimeline(Twitter.java:1153)
09-11 03:58:37.118    3187-3204/com.sunsystems.yambaapp W/System.err﹕ at com.sunsystems.yambaapp.UpdateService$GetHomeStatus.doInBackground(UpdateService.java:70)
09-11 03:58:37.118    3187-3204/com.sunsystems.yambaapp W/System.err﹕ at com.sunsystems.yambaapp.UpdateService$GetHomeStatus.doInBackground(UpdateService.java:61)
09-11 03:58:37.128    3187-3204/com.sunsystems.yambaapp W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:287)
09-11 03:58:37.128    3187-3204/com.sunsystems.yambaapp W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:234)
09-11 03:58:37.128    3187-3204/com.sunsystems.yambaapp W/System.err﹕ at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
09-11 03:58:37.128    3187-3204/com.sunsystems.yambaapp W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
09-11 03:58:37.128    3187-3204/com.sunsystems.yambaapp W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
09-11 03:58:37.128    3187-3204/com.sunsystems.yambaapp W/System.err﹕ at java.lang.Thread.run(Thread.java:841)

回答1:


I was able to reproduce the said exception using JTwitter 2.9.0. Reason for my earlier suggestion was:

List<winterwell.jtwitter.Status> timeline;

I was using a modified version of JTwitter library: JTwitterYamba. This library does not contain winterwell.jtwitter.Status. Instead Status is an inner class defined in winterwell.jtwitter.Twitter making its fully qualified path: winterwell.jtwitter.Twitter.Status.

List<winterwell.jtwitter.Twitter.Status> timeline;

So, instead of asking you to lose JTwitter jar and add JTwitterYamba jar, I suggested the exact opposite. Sorry about the confusion.

The problem:

Both libraries implement Twitter.getFriendsTimeline() differently. Here's what JTwitterYamba does:

public List<Status> getFriendsTimeline() throws TwitterException {

    // Take note of the URL suffix: /statuses/friends_timeline.json
    return getStatuses(TWITTER_URL + "/statuses/friends_timeline.json",
        standardishParameters(), true);
}

And, here's what JTwitter does:

@Deprecated
public List<Status> getFriendsTimeline() throws TwitterException {
    return getHomeTimeline();
}


public List<Status> getHomeTimeline() throws TwitterException {
    assert http.canAuthenticate();

    // The URL isn't the same
    return getStatuses(TWITTER_URL + "/statuses/home_timeline.json",
                         standardishParameters(), true);
}

What you can do to fix this:

You can remove JTwitter from your project and add JTwitterYamba jar: Link. You will have to change winterwell.jtwitter.Status to winterwell.jtwitter.Twitter.Status.

Alternatively, you can check if modifying the library is allowed and possible for you. Add a public method that uses TWITTER_URL + "/statuses/friends_timeline.json" as one of the arguments for Twitter.getStatuses method.




回答2:


Marakana redirects to thenewcircle as they were acquired by twitter.

According to this page there are two things to try...

Get the .jar from the apk by right-clicking on your project, select Properties and go to Java build path. In there go to the tab Order and Export and check jtwiiter-yamba.jar. Also remove these hardcoded lines

// twitter = new Twitter("student", "password");
// twitter.setAPIRootUrl("http://yamba.marakana.com/api");


来源:https://stackoverflow.com/questions/18848001/alternative-for-getpublictimeline-for-jtwitter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!