issue in direct messages using streaming api

Jul 6, 2015 at 11:13 AM
hi,
i am trying to send direct messages using streaming api. but i am not able to receive any message which i have sent on my console.
i am using the following code...
var stream = Stream.CreateUserStream();
           stream.MessageSent+=(sender, a)=>
            {
                Console.WriteLine("User posted : ", a.Message.Text);
            };
            stream.StartStream();
Coordinator
Jul 6, 2015 at 11:45 AM
Are you sure that you are sending a message and not a tweet?
  • Messages are used to privately communicate between 2 users
  • Tweets are usually public and displayed on the user Timeline
I just want to be sure that you are creating Messages and not tweets before investigating this issue.

Cheers,
Linvi
Jul 7, 2015 at 5:58 AM
i am sending a message....
Coordinator
Jul 7, 2015 at 11:10 AM
Hi.

I just wanted this to be confirmed as I am not able to reproduce your issue.

Would you please confirm that the following code is not raising the event.
var us = Stream.CreateUserStream();

us.MessageSent += (sender, args) =>
{
    Console.WriteLine(args.Message);
};

us.FriendIdsReceived += (sender, args) =>
{
    var message = Message.PublishMessage("i love tweetinvi messaging! " + Guid.NewGuid().ToString(), "YOUR_TARGET_USER");

    if (message != null)
    {
        Console.WriteLine("message has been published!");
    }
    else
    {
        Console.WriteLine("message has not been published!");
    }
};

us.StartStream();
What I am doing over there is that I publish a message when the stream is ready to receive the event.

Could you also disable the Exception Handler so that any exception throws.
ExceptionHandler.SwallowWebExceptions = false;
Please let me know if this code works or if you receive any Exception.

Cheers,
Linvi
Jul 7, 2015 at 1:44 PM
Hi,

Yes, the event is not getting fired inside the function. I did put a breakpoint over there but the event is not fired.
private static void Stream_UserStreamExample()
        {
            var userStream = Stream.CreateUserStream();


            // Messages
            EventsRelatedWithMessages(userStream);    //I am using my application for Messages.

            // User Update
            userStream.LoggedUserProfileUpdated += (sender, args) =>
            {
                var newLoggedUser = args.LoggedUser;
                Console.WriteLine("Logged user '{0}' has been updated!", newLoggedUser.Name);
            };

            // Friends the stream will analyze - A UserStream cannot analyze more than 10.000 people at the same time
            userStream.FriendIdsReceived += (sender, args) =>
            {
                var friendIds = args.Value;
                Console.WriteLine(friendIds.Count());
            };

            // Access Revoked
            userStream.AccessRevoked += (sender, args) =>
            {
                Console.WriteLine("Application {0} had its access revoked!", args.Info.ApplicationName);
            };

            userStream.StartStream();
        }


        private static void EventsRelatedWithMessages(IUserStream userStream)
        {


            //These events didn't get fired when I send/receive Direct Messages.

            userStream.MessageSent += (sender, args) => { Console.WriteLine("message '{0}' sent", args.Message.Text); };
            userStream.MessageReceived += (sender, args) => { Console.WriteLine("message '{0}' received", args.Message.Text); };
        }
Thanks
Coordinator
Jul 7, 2015 at 3:54 PM
Hi,

Thank you for the reply.

Could you please try and check if any of the 2 following events are being raised when you send a message.
var us = Stream.CreateUserStream();
us.UnmanagedEventReceived += (sender, args) =>
{
    Console.WriteLine("unexpected message received");
    Console.WriteLine(args.JsonMessageReceived);
};

us.JsonObjectReceived += (sender, args) =>
{
    Console.WriteLine("Json Received!");
    Console.WriteLine(args.Json);
};

If any of these are being raised when you send a message, please give me value of the Json.

Thanks,
Linvi
Jul 8, 2015 at 10:50 AM
Hi,

Thanks for replying.

I tried to change the code as you suggested but still no events got raised. I am getting a screen indefinitely timed with text:
https://www.api.twitter.com/1.1/account/verify_credentials.json
https://www.userstream.twitter.com/1.1/user.json?stall_warnings=true&replies=all&with=followings
...
But when I am sending/receiving messages through twitter, I am not getting them here.

Thanks
Vik
Coordinator
Jul 8, 2015 at 1:01 PM
Edited Jul 8, 2015 at 1:03 PM
Hi,

The debug information are correct, and yes you will have a screen indefinitely timed.
If you want the stream to let your application continue, you will need to call the async version of StartStream or call it in another Thread.
stream.StartStreamAsync();
Would you please confirm that you authorized your app to access the DirectMessages?
You can do that just here:

https://apps.twitter.com/app/__YOUR_APP_ID_HERE__/permissions

Are you currently using a version 0.9.8.x of Tweetinvi?

If the permissions are set correctly and you are using version 0.9.8.x of Tweetinvi I will need you to share your credentials and your code privately with me.

Thanks for your understanding.
Linvi
Jul 8, 2015 at 2:02 PM
Hi,

yes i am using version 0.9.8.x of Tweetinvi and my app is authorized to access direct messages.
i can share my app credentials and code, for that i need your email address.

Thanks for replying..
Coordinator
Jul 8, 2015 at 8:46 PM
Hi,

I have sent you an email through you contact page. You can reply to it directly.

Regards,
Linvi
Coordinator
Jul 15, 2015 at 6:22 PM
For future reference. The issue was network related. The code and the tweetinvi library worked as expected.
Marked as answer by linvi on 7/15/2015 at 10:22 AM