tweetinvi, I can't retrieve messages - c#

I want to monitor retrieve messages so that the bot can respond to them.
I can send pm using tweetinvi but for some reason, I can't get it to retrieve any of the messages in that account. GetLastMessage always returns a null.
I have tried the following:
in this test, I have a timer that runs every 1s and pols the messages.
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 also tried using
IAuthenticatedUser authenticatedUser = User.GetAuthenticatedUser();
authenticatedUser.GetLatestMessagesReceived();
I am using
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.

Your app must have permission to read and write on twitter API.

Related

Google API Client returning 404 not fund

I am trying to get the best searches from google, using keyword, and GoogleAPI, but It is always returning "System.Net.WebException: 'The remote server returned an error: (404) Not Found.'"
Am I doing anything wrong, or is it that GoogleAPI is outdated? Last time I checked and downloaded the .dll file was from 2010...
code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.IO;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
using System.Threading;
using System.Diagnostics;
using System.Collections;
using Microsoft.Win32;
using System.Web;
using System.Net.Mail;
using System.Net.Mime;
using System.ComponentModel;
using System.Net;
using System.Windows;
using Google.Apis.Services;
using Google.Apis.CustomSearchAPI.v1;
//Ignore most using statements, It was imported from my previous code.
namespace TYZDsag
{
internal class Program
{
static void Main(string[] args)
{
var client = new Google.API.Search.GwebSearchClient("https://www.google.com/");
var results = client.Search("uhuhuh", 12);
foreach (var webResult in results)
{
Console.WriteLine("{0}, {1}, {2}", webResult.Title, webResult.Url, webResult.Content);
//listBox1.Items.Add(webResult.ToString());
}
}
}
}
That's not how you initialize a service object using an api key.
using System;
using System.Threading.Tasks;
using Google.Apis.CustomSearchAPI.v1;
using Google.Apis.Services;
namespace customsearch
{
class Program
{
static async Task Main(string[] args)
{
Console.WriteLine("Hello World!");
var service = new CustomSearchAPIService(new BaseClientService.Initializer()
{
ApiKey = "XXX",
ApplicationName = "xyz",
});
var result = await service.Cse.List().ExecuteAsync();
}
}
}
Method: cse.list
How to create an api key

How to send a simple message using a twilio number with an ASP.NET MVC project?

I am trying to change and edit the code but it returns with exceptions errors in regards authentication errors. The username cannot be null as well as the category is not able to load the code. Another exception that is running on it is the Twilio.Exceptions.ApiExecution that requires a phone number.
The documentation is here: https://www.twilio.com/docs/sms/tutorials/server-notifications-csharp-mvc?code-sample=code-csv-list-of-phone-numbers-to-notify&code-language=csv&code-sdk-version=default
The video to build the code for integrating Twilio in an ASP.net MVC project is here: https://www.youtube.com/watch?v=ndxQXnoDIj8
The code excerpt is here:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Configuration;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
using Twilio.Types;
using Twilio.TwiML;
using Twilio.AspNet.Mvc;
namespace SendandReceiveSms.Controllers
{
public class SMSController : TwilioController
{
// GET: SMS
public ActionResult SendSms()
{
var accountSid = ConfigurationManager.AppSettings["TwilioAccountSid"];
var authToken = ConfigurationManager.AppSettings["TwilioAuthToken"];
TwilioClient.Init("ACa4XXXXXXXXXX","77XXXXXXXXXX");
var to = new PhoneNumber(ConfigurationManager.AppSettings["+65XXXXXXXX"]);
var from = new PhoneNumber("+12053016835");
var message = MessageResource.Create(
to: to,
from: from,
body: "Conserve with us and save the Wolrd ");
return Content(message.Sid);
}
public ActionResult ReceiveSms()
{
var response = new MessagingResponse();
response.Message(" We turn waste into environmental assets");
return TwiML(response);
}
}
}
You can try this also.
using DocGen.Notifications.Contract;
using DocGen.Notifications.Models;
using System;
using System.Configuration;
using System.Linq;
using System.Text;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
using Twilio.Types;
namespace DocGen.Notifications.Providers
{
public class SmsNotificationProvider : INotificationProtocolContract
{
NotificationResponseModel notificationResponseModel = new NotificationResponseModel();
public NotificationResponseModel SendNotification(NotificationRequestModel notificationRequestModel)
{
if (notificationRequestModel.SmsTo == null || notificationRequestModel.SmsTo.Count() == 0)
throw new ArgumentNullException(nameof(notificationRequestModel.SmsTo));
TwilioClient.Init(ConfigurationManager.AppSettings["accountSid"], ConfigurationManager.AppSettings["authToken"]);
foreach (var Sms_to in notificationRequestModel.SmsTo)
{
var to = new PhoneNumber(Sms_to);
var message = MessageResource.Create(
to,
from: new PhoneNumber(ConfigurationManager.AppSettings["senderNumber"]),//"+12563054795"
body: Encoding.UTF8.GetString(notificationRequestModel.Message));
notificationResponseModel.ResponseMessage = message.Status.ToString();
}
//notificationResponseModel.ResponseMessage = "Message Successfully sent.";
return notificationResponseModel;
}
}
}

How to detect the NFC (ACR122U) reader and read the ID value of the tag, using Smartcard API

I try to read the ID of a NFC tag with the SmartCard API, I'm sure there is not much code to implement but I'm totally lost. Here is the code i could provide.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Barcode
{
class MifareCardConfigData
{
byte[] UID = null;
byte[] m_serialNumber = null;
public MifareCardConfigData(SmartCardAPI.CardModule.CLICS.ClicsCardEdge MifareCard)
{
UID = MifareCard.UID;
Array.Resize(ref m_serialNumber, UID.Length);
}
}
}

How to Generate Text File from API Source?

I have a small problem. I just recently started using Twilio's API to generate a record of messages that was sent to my assigned SID and Auth Token. However my question is how can I generate a text file, based off of what the console writes from the source its addressed to?
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading.Tasks;
using Twilio;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
// Find your Account Sid and Auth Token at twilio.com/user/account
string AccountSid = "X";
string AuthToken = "X";
var twilio = new TwilioRestClient(AccountSid, AuthToken);
// Build the parameters
var options = new MessageListRequest();
options.From = "2015-07-01";
options.To = "2015-07-13";
var messages = twilio.ListMessages(options);
foreach (var message in messages.Messages)
{
Console.WriteLine(message.Body);
Console.Read();
}
}
}
}
Writing to a text file is pretty much boilerplate. The methods are shown here:
https://msdn.microsoft.com/en-us/library/8bh11f1k.aspx

Why doesn't my code-behind execute?

I am trying to output the value of x in the following request: http://localhost:4827/Default.aspx?x=123123
I am getting no output at all.
Here is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using MPads.Common;
using MPads.WebPatientPortal.Interfaces;
using MPads.WebPatientPortal.Presenters;
using MPads.BusinessLogic.Interfaces;
using MPads.Components.Interfaces;
using MPads.DataAccess;
using MPads.DataAccess.Interfaces;
using System.Text;
using System.Diagnostics;
namespace MPads.WebPatientPortal
{
public partial class Default : System.Web.UI.Page, IDefault
{
private DefaultPresenter _presenter;
protected void Page_Load(object sender, EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
_presenter = new DefaultPresenter();
var fields = Request.QueryString;
if (fields.Count > 0)
{
var x = Utilities.GetNvpValue(fields, "x").ToString();
Trace.Write(x);
}
}
public void loadAjaxContent(string content)
{
Page.RegisterStartupScript("myScript", " <script type=\"text/javascript\"> loadAjaxContent('" + content + "','POST',null); </script>");
}
public void DisplayMessage(string message)
{
}
}
}
Do you have your even handler set up in your ASPX?
Assuming that you do: Consider instead of Trace.Write(); using Response.Write();
Trace.Write(); writes to a trace listener (which you can have display at the bottom of your page).
Response.Write(); outputs text results directly to your page, not through a Trace Listener.
Use Glimpse to find out this, here's the link Glimpse-A client side Glimpse to your server

Categories

Resources