I can't retrieve messages using tweetinvi

csharp
tweetinvi

#1

I am developing services where users get very specific information sent to them via direct messages on demand.

I am using C# and the tweetinvi library. As I want the users to be able to query the services, op-in and op-out I need to retrieve messages.

for development, I have a timer that polls the twitter account and check for new direct messages.

I can send DM to followers from the account but can’t retrieve any messages send or received.

But all I get is a null from getlastmessages.

private static void OnTwitterTimedEvent(Object source, System.Timers.ElapsedEventArgs e)
{
    try
    {
        IEnumerable<IMessage> MSG  = controller.GetLatestMessagesReceived(); ; // Message.GetLatestMessagesReceived(100);

        if (MSG != null)
        {
            Console.WriteLine(MSG.ElementAt(0).SenderScreenName + MSG.ElementAt(0).Text);

            if ((MSG.ElementAt(0).SenderId == ####MYID#####) & (MSG.ElementAt(0).Text == "?"))
            {
                Message.PublishMessage(tweet, ####MYID#####);
                Console.ForegroundColor = ConsoleColor.DarkGreen;
                Console.WriteLine(MSG.ElementAt(0).SenderScreenName + MSG.ElementAt(0).Text);
                Console.ResetColor();
                Message.DestroyMessage(MSG.ElementAt(0));
            }
        }
    } catch
    {
        }

}

I have also tried

private static void OnTwitterTimedEvent(Object source, System.Timers.ElapsedEventArgs e)
    {

        try
        {
            var latestMessagesSent = Message.GetLatestMessagesSent();
            var latestMessagesSentParameter = new MessagesSentParameters();
            latestMessagesSentParameter.PageNumber = 239823;
            var latestMessagesSentFromParameter = Message.GetLatestMessagesSent(latestMessagesSentParameter);

            if (latestMessagesSentFromParameter != null)
            {
                Console.WriteLine("Messages Send : ");
                foreach (var mms in latestMessagesSentFromParameter)
                {
                    Console.WriteLine("- '{0}'", mms.Text);
                }

            }
        } catch
        {
        }

    }

I have also tried

IAuthenticatedUser authenticatedUser = User.GetAuthenticatedUser(); authenticatedUser.GetLatestMessagesReceived();

In the mains I am using the following.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Timers;
using System.Threading.Tasks;
using System.Collections;
using System.Globalization;
//using System.Threading;
using System.IO;
using System.Net;
using System.Diagnostics;
using System.Net;
using System.Reflection;

// REST API
using Tweetinvi;
using Tweetinvi.Models;
using Tweetinvi.Parameters;

// STREAM API
using Tweetinvi.Streaming;
using Stream = Tweetinvi.Stream;

// Others
using Tweetinvi.Exceptions; // Handle Exceptions
using Tweetinvi.Core.Extensions; // Extension methods provided by Tweetinvi
using Tweetinvi.Models.DTO; // Data Transfer Objects for Serialization
using Tweetinvi.Json; // JSON static classes to get json from Twitter.

#2

The app does have read, write and DM permissions


#3

Hello, did you try to regenerate your credentials?


#4

Hi. Working. I had to delete the keys and make new keys.


#5