Adapter.setTweetId seems to be unable to load the tweets but doesn't fire a success/failure callback


#1

Hey guys,

I’ve integrated twitter into my app by retrieving the information of the latest tweets, read the tweet ids ouf of the response and pass them to an adapter provided by the API which I set for my listview. So all the code I am actually doing myself is doing a request to get the tweets data and parse for their ids. This worked absolutely fine before…

Suddenly it stopped working without any change being done to the code. What is even more confusing is the part that I am doing myself (parsing for the ids) is still working fine (there is a response from the twitter api and parsing for the ids gives a legitimate result). However displaying via the adapter just stopped working.

I haven’t found any issues so I desperately tried to login at
I’m VERY confused at this point. Since the issue seems from my perspective to be pretty much in the API objects. To display the tweets of my IDs I use TweetViewFetchAdapter and just pass my IDs via setTweetIds.

(Note: I also tried to move to https://dev.twitter.com/twitter-kit/android/show-timelines and use this approach as an authorized account is not really needed for the task at hand right now, but I didn’t get anything displayed at all which seems odd as it looks fairly easy and there is not a lot of stuff to adjust) If I use a simple array adapter and fill it with text displaying that works fine.

Sorry for the long post I tried to post as much details as I can. Please help me and a lot of thanks in advance!


#2

Hey there,

Are you getting any errors in the log?

V


#3

hey,

I don’t get any debug messages from twitter. I’ve tried quite hard to debug in the last few hours. The issue is related to this code snippet:

 @Override
            protected void onPostExecute(List<Long> params){
                if (params != null && params.size() > 0) {
                    adapter.setTweetIds(params,
                            new LoadCallback<List<Tweet>>() {
                                @Override
                                public void success(List<Tweet> tweets) {
                                    Log.i("twitter", "Success!");
                                }
                                @Override
                                public void failure(TwitterException exception) {
                                    Log.e("twitter", "Exception: " + exception.getMessage());
                                }
                            });
                }
                Log.i("twitter", "params.size = " + params.size() + " adapter.tweetCount = " + adapter.getCount());
            }

I am unable to debug the LoadCallback success or failure. Neither do I see any log output nor am I able to step into those methods with the debugger (the breakpint simply gets skipped just as if the method would never be called.

Also the output I get for the last Log message suggests, that something in setTweetIds is going wrong: I/twitter﹕ params.size = 10 adapter.tweetCount = 0

Side note: My current approach is quite horrible to display some tweets, but I’d still be curious why it is not workign at all (and it did indeed work before). The Id’s in params are retrieved by using an API call to user_timeline.json, so they are most definetly not invalid IDs.


#4

I’m experiencing the exact same issue, no logs on my end either. What’s more, I’ve also tried using TweetViewAdapter as well as TweetUtils.loadTweets, and neither works. Essentially nothing in the TweetUi kit is working, and I’m not getting any crashes, no callbacks, and no logs.


#5

I’ve been thinking it may be caused by a missing layout file or something like that. But since I don’t really know what the plugin is doing (I really dislike to be forced to use this is there a workaround!?) I’m really unsure how to look into this. A error message would be helping so much…

But I’m glad I’m not the only one experiencing this issue… I could write the Tweet Layout myself and use a normal ArrayAdapter (or even use the existing tweet layout if possible) but I definetly feel like the API is broken regarding the Adapter class…


#6

Completely agree. I’m trying to find a workaround too but so far no luck. I’ve tried sending it bogus tweet IDs in the hope that it would fire back the failure callback, but again nothing happens. I’ve also tried using several different older versions of the SDK with no luck. I’ve also tried just creating a single tweet view using TweetUtils.loadTweet, but again the callbacks don’t get fired there, so I don’t think the problem is limited to the adapter but rather the entire TweetUi kit.

It’s entirely possible that we are both missing something subtle, but it is extremely frustrating that there are no log messages and the callbacks don’t fire at all (kind of defeats the purpose of having a failure callback in the first place). If it were open source we could at least figure out what was going on under the hood, but that isn’t the case either.


#7

I’ve also tried UserTimeline (because I want to display a public timeline) and it didn’t work for no reason. Now I go back to WebView and try to display it using this.

As a workaround I think the only way for me would be right now to copy the tweet layout and fill it with data from user_timeline.json (as those requests are working fine for me). But it is a really ugly solution…


#8

Yea I’m doing something similar on my end, I’ve given up on TweetUi kit and am just building my own UI from the response of the search REST API.


#9

You could try to copy the tweet layout from it’s source and just fill it’s parameter with the stuff you get from the REST API. At least I found the general tweets layout in some generated folder. If that works out you could use the layout in an ArrayAdapter or something similiar and it shouldn’t be too much work I think.

But I’ve given up on this, I’ll just use WebView :p.


#10

Sorry you’re having troubles. Silently not working sounds unusual. Can I get more details about what is working in your setup and what’s not?

How are you setting up the adapter shown in the code example? Are you able to call TweetUtils.loadTweet or TweetUtils.loadTweets and get Tweets back? If not, how are you setting up the TweetUi kit? Are you able to make requests through the twittercore API services? I can’t think of a misconfiguration which would not result in any outputs at all, but sharing that setup might surface something amiss. Have you tried setting Fabric debuggable(true) using the Fabric Builder?

final Fabric fabric = new Fabric.Builder(this)
                .kits(new Twitter(authConfig))
                .logger(new DefaultLogger(Log.DEBUG))
                .debuggable(true)
                .build();
Fabric.with(fabric);

Have you set breakpoints to verify params are what you expect and your code gets called, but neither of the callbacks are invoked? - since info logging may not always be shown. The example you provide loads tweet 20 and invokes the success callback for me.

List<Long> params = new ArrayList<>();
params.add(20L);
adapter.setTweetIds(params,
    new LoadCallback<List<Tweet>>() {
           @Override
           public void success(List<Tweet> tweets) {
               Log.d("twitter", "Success!");
           }
           @Override
            public void failure(TwitterException exception) {
              Log.e("twitter", exception.getMessage());
           }});

Feel free to email support@fabric.io detailed code if you don’t wish to share it here.


#11

Hey there,

I haven’t been able to work on this over the last few days, so sorry for the late response!

It seems something within the initialization of fabric is going wrong as I get an illegal state exception. I get this exception for the first time with the init code you’ve provided (except adding the TweetUi kit as well!)

     Caused by: java.lang.IllegalStateException: Must Initialize Fabric before using singleton()
        at io.fabric.sdk.android.Fabric.singleton(Fabric.java:253)
        at io.fabric.sdk.android.Fabric.getKit(Fabric.java:501)
        at com.twitter.sdk.android.tweetui.TweetUi.checkInitialized(TweetUi.java:107)
        at com.twitter.sdk.android.tweetui.TweetUi.getInstance(TweetUi.java:55)
        at com.twitter.sdk.android.tweetui.TweetViewFetchAdapter.setTweetIds(TweetViewFetchAdapter.java:77)

I’ve checked via log when I call the fabric init code and when I call setTweetIds and the order is fine, fabric should be initiated BEFORE I call setTweetIds, based on the logs! The exception only occurs if I use your init snippet, if I use my own

TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
    Fabric.with(context, new Twitter(authConfig), new TweetUi());

I won’t get any exception but of course it is not working too… (The authConfig is the same in both init versions!)

If I use my own init code snippet then the example you’ve provided (load tweet 20) doesn’t work. I don’t get any log output…
One thing I have in mind is that there may be an context issue? But the context I use to initialize is the same as the one in which I call setTweetIds (or any TweetUi stuff for that matter)

Thanks for your help! Please let me know if you need any more code.


#12

Calling Fabric.with is still needed, I’ve updated my example to show that explicitly. Also, if you’re using the Twitter kit, you don’t need to add TweetUi, its included. See the note at the bottom of https://dev.twitter.com/twitter-kit/android/tweetui


#13

Sorry for my late response once again, I only work part time on this, therefore my response time is a little bit high. I’m sorry!

Okey so finally after 100 rebuilds android is using the updated okhttp and okhttp-urlconnection from build.gradle. This also seems to have fixed my issue and everything is working as it did before now. I’m assuming there has been an update to a newer okhhtp version, tho I checked the changelog and my code stopped working before the dependencies got updated to okhttp 2.0.+

Anyhow everything is fine now. If other people have issues try updating your dependencies with these:

dependencies {
// ...
compile 'com.squareup.okhttp:okhttp:2.3.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.3.0'
}

It is still weird that I didn’t get any output message at all without the default fabric configuration.


#14

The issue (for me) was probably related to (I think!) an update of the okhttp and okhhtp-urlconnection dependencies. Update those in my build.gradle fixed the issue (tho it felt like I had to do 100 rebuilds until it finally used the newer version…)

See my post below for detailed information.


#15