[Stream API] Unable to listen for any events on WP8.1

Jul 15, 2015 at 11:40 AM
Edited Jul 15, 2015 at 11:41 AM
Hi,

I'm tryin to use Streams to avoid periodic Timeline update but I'm unable to fetch any data.

The same also apply when using SampleStream:
await ThreadPool.RunAsync(async (work) => {

      var sampleStream = Tweetinvi.Stream.CreateSampleStream();

      sampleStream.TweetReceived += (sender, args) =>
      {
            Debug.WriteLine("Received Tweet: " + args.Tweet.Text);
      };

       sampleStream.JsonObjectReceived += (sender, args) =>
      {
            Debug.WriteLine("Received JSON: " + args.Json);
      };

      sampleStream.UnmanagedEventReceived += (sender, args) =>
      {
            Debug.WriteLine("UnmanagedEventReceived " + args.JsonMessageReceived);
      };

      await sampleStream.StartStreamAsync();

});
It seems that only the first message is received:

Received JSON: {"created_at" (..)
Received Tweet: <same text here> (...)

In fact, with UserStream I correctly receive all the Ids of the logged user, but nothing else.

To reproduce you can create a blank project for Windows Phone 8.1 and than place the code above in the OnNavigatedTo(NavigationEventArgs e) event.

TY.

Manuel
Coordinator
Jul 15, 2015 at 12:52 PM
Hi Manuel,

Could you please let me know if you encounter the same issue any other type of project (console, wpf, web...)?

Linvi
Jul 15, 2015 at 2:02 PM
Edited Jul 17, 2015 at 7:02 AM
No problem with a console app!

UPDATE: tried playing with WorkItemPriority but the event never fires twice.

UPDATE2: to discard any problems related to the network layer I also tried under Wi-Fi without resolve the problem.
Jul 17, 2015 at 7:26 AM
Edited Jul 17, 2015 at 9:40 AM
I've add some debug on others event listener:

URL : https://stream.twitter.com/1.1/statuses/sample.json?stall_warnings=true
Code : 408
Error documentation description : Twitter was not able to perform your query within the Timeout limit of 0 ms.
Init sample stream
Received JSON: {"created_at" (...)
Received Tweet: @piercethelela look on (...)
StreamStopped  --- Date : (...) 
URL : https://stream.twitter.com/1.1/statuses/sample.json?stall_warnings=true
Code : 408
Error documentation description : Twitter was not able to perform your query within the Timeout limit of 0 ms.
Jul 22, 2015 at 8:11 AM
Edited Jul 22, 2015 at 8:12 AM
I've created a small project to reproduce the issue. You can find it here -> http://1drv.ms/1efO5ZP

If you want start from scratch:
  1. create a blank universal project with VS2013;
  2. install Tweetinvi 0.9.8.2 with nuget both on Windows Phone and Windows;
  3. set manifest capabilities for Windows: Internet (client), Internet (client e server) and Private Network (client e server);
  4. set manifest capabilities for Windows Phone: Internet (client e server);
  5. added snipped for sample stream start at app startup (App.xaml.cs).
With Windows Phone you should get 408, on Windows seems to work well.

Snipped:
Debug.WriteLine("Set cred...");

String accessToken = "";

String accessSecret = "";

String consumerKey = "";

String consumerSecret = "";

TwitterCredentials.SetCredentials(accessToken, accessSecret, consumerKey, consumerSecret);

Debug.WriteLine("Init sample stream");

var sampleStream = Tweetinvi.Stream.CreateSampleStream();

sampleStream.TweetReceived += (sender, args) =>
{
    Debug.WriteLine("Received Tweet: " + args.Tweet.Text);
};

sampleStream.JsonObjectReceived += (sender, args) =>
{
    Debug.WriteLine("Received JSON: " + args.Json);
};

sampleStream.UnmanagedEventReceived += (sender, args) =>
{
    Debug.WriteLine("UnmanagedEventReceived " + args.JsonMessageReceived);
};

sampleStream.DisconnectMessageReceived += (sender, args) =>
{
    Debug.WriteLine("DisconnectMessageReceived " + args.DisconnectMessage);
};

sampleStream.WarningFallingBehindDetected += (sender, args) =>
{
    Debug.WriteLine("WarningFallingBehindDetected " + args.WarningMessage);
};

sampleStream.LimitReached += (sender, args) =>
{
    Debug.WriteLine("LimitReached " + args.NumberOfTweetsNotReceived);
};

sampleStream.StreamStopped += (sender, args) =>
{
    Debug.WriteLine("StreamStopped " + args.DisconnectMessage + " " + args.Exception);
};

sampleStream.StreamPaused += (sender, args) =>
{
    Debug.WriteLine("StreamPaused");
};

sampleStream.StartStream();
Coordinator
Jul 22, 2015 at 10:53 AM
Hi,

Sorry I forgot about this issue because I forgot to add it into the issue backlog.
I have now created a new work item for this : https://tweetinvi.codeplex.com/workitem/2619. (you can vote if you want to get notified of updates).

Could you please let me know if you encounter the same issue on the Windows Phone emulator? Also do you encounter the same issue on Windows 8.1 RT?

I will work on this as soon as I can, I will probably have an hour to spare tonight but I will be quite busy until next Tuesday.

Linvi
Jul 22, 2015 at 11:19 AM
Edited Jul 22, 2015 at 11:21 AM
linvi wrote:
Hi,

Sorry I forgot about this issue because I forgot to add it into the issue backlog.
I have now created a new work item for this : https://tweetinvi.codeplex.com/workitem/2619. (you can vote if you want to get notified of updates).

Could you please let me know if you encounter the same issue on the Windows Phone emulator? Also do you encounter the same issue on Windows 8.1 RT?

I will work on this as soon as I can, I will probably have an hour to spare tonight but I will be quite busy until next Tuesday.

Linvi
Grazie linvi!

On Windows Phone emulator I get some data than after some time the 408 error.
The curious thing is that in task manager I can see the emulator receiving data from the net.

Image

With Windows 8.1 RT (simulator -> this one) I can correctly see the tweets of the stream being received and logged in the console.
Coordinator
Jul 22, 2015 at 12:10 PM
Oh wait,

Can you try using sampleStream.StartStreamAsync() instead of sampleStream.StartStream().

Linvi
Jul 22, 2015 at 1:28 PM
Of course.

Unfortunately same behavior as the syncronous methods.
Coordinator
Jul 22, 2015 at 9:26 PM
Edited Jul 22, 2015 at 9:26 PM
Hi,

This does not seem to be working in the App.xaml, but if you put it in a View it works correctly. I remember reading about this.

So here is what I did (Visual Studio 2013) :
  • Create Pivot Universal Project
  • Install-Package TweetinviAPI (targeting Windows Phone project)
  • Open PivotPage.xaml
  • Edit the constructor as followed:
public PivotPage()
{
    this.InitializeComponent();

    this.NavigationCacheMode = NavigationCacheMode.Required;

    this.navigationHelper = new NavigationHelper(this);
    this.navigationHelper.LoadState += this.NavigationHelper_LoadState;
            
    this.navigationHelper.SaveState += this.NavigationHelper_SaveState;
    this.Loaded += OnLoaded;
}

private void OnLoaded(object s, RoutedEventArgs routedEventArgs)
{
    TwitterCredentials.SetCredentials(...);
    var stream = Tweetinvi.Stream.CreateSampleStream();
    stream.TweetReceived += (sender, args) =>
    {
        Debug.WriteLine(args.Tweet);
    };

    stream.StartStreamAsync();
}
Done!
Jul 23, 2015 at 7:14 AM
Edited Jul 23, 2015 at 10:54 AM
No matter where I put the code, in my env the results are always the same (I put in the App.xaml only to be sure that the code executed is the same in WinRT for Windows and Windows Phone). Can you share you project with the stream working on phone?

In my VS2013 I've not the Pivot Universal Project...maybe you are referring to the Hub Project?

Now I'm downloading VS2015 to try from scratch again.

EDIT: no luck even with VS2015.
Coordinator
Jul 23, 2015 at 4:55 PM
Hi,

I do not have access to the computer where I did this. I won't be able to give you this right away but as soon as I can I will definitely send it to you.
I guess I will create a VM and send you a new project from there.

Linvi
Jul 24, 2015 at 9:45 AM
Thank you, much appreciate.
Coordinator
Jul 25, 2015 at 3:17 AM
I have just realized that I tried on a Windows Phone app and not a Universal App.
I will get back to you when I have tried on a Universal App; probably tomorrow.
Jul 25, 2015 at 8:26 AM
A Windows Phone only project is also a perfect match if you ask me...
Coordinator
Jul 26, 2015 at 11:29 PM
Hi, you can find this example here:

http://we.tl/C9mFS4lscD

Let me know if this works for you (App1 project).
Jul 27, 2015 at 7:26 AM
Edited Jul 27, 2015 at 7:32 AM
Can't open the project...

Image

It will be best to create a new project with nuget packages istead of project references, if we want the problem to be replicated.
Aug 4, 2015 at 11:41 AM
Tested today in an uap project.

Stream works well also. You can mark as resolved the issue! Thank you!
Marked as answer by linvi on 8/6/2015 at 8:12 AM