Reputation: 69
I have been trying to get tweetinvi to work and it always returns null for whatever I do. I have tried 3 of the queries with search, rate limit and logged in user and all return null. Dont know what i've done wrong :s first time I have tried to use twitter api
Form1
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using Tweetinvi;
using Tweetinvi.Core.Enum;
using Tweetinvi.Core.Extensions;
using Tweetinvi.Core.Interfaces;
using Tweetinvi.Core.Interfaces.Controllers;
using Tweetinvi.Core.Interfaces.DTO;
using Tweetinvi.Core.Interfaces.DTO.QueryDTO;
using Tweetinvi.Core.Interfaces.Models;
using Tweetinvi.Core.Interfaces.Models.Parameters;
using Tweetinvi.Core.Interfaces.oAuth;
using Tweetinvi.Core.Interfaces.Streaminvi;
using Tweetinvi.Json;
using System.Windows.Forms;
namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// TwitterCredentials.SetCredentials("xx", "xx", "xx", "xx");
}
public void Search_SimpleTweetSearch()
{
// IF YOU DO NOT RECEIVE ANY TWEET, CHANGE THE PARAMETERS!
var tweets = Search.SearchTweets("hi");
foreach (var tweet in tweets)
{
// Console.WriteLine("{0}", tweet.Text);
textBox1.Text += "tweet.Text" + System.Environment.NewLine;
}
}
public void test()
{
var user = User.GetLoggedUser();
textBox1.Text += user.ScreenName + System.Environment.NewLine;
}
private void button1_Click(object sender, EventArgs e)
{
test();
// Search_SimpleTweetSearch();
}
private void button2_Click(object sender, EventArgs e)
{
var rateLimits = RateLimit.GetCurrentCredentialsRateLimits();
textBox1.Text += rateLimits.ToString() + System.Environment.NewLine;
}
}
}
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Tweetinvi;
using Tweetinvi.Core.Enum;
using Tweetinvi.Core.Extensions;
using Tweetinvi.Core.Interfaces;
using Tweetinvi.Core.Interfaces.Controllers;
using Tweetinvi.Core.Interfaces.DTO;
using Tweetinvi.Core.Interfaces.DTO.QueryDTO;
using Tweetinvi.Core.Interfaces.Models;
using Tweetinvi.Core.Interfaces.Models.Parameters;
using Tweetinvi.Core.Interfaces.oAuth;
using Tweetinvi.Core.Interfaces.Streaminvi;
using Tweetinvi.Json;
namespace WindowsFormsApplication4
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
TwitterCredentials.SetCredentials("xx", "xx", "xx", "xx");
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
Upvotes: 2
Views: 1971
Reputation: 3601
You can get more information on what has gone wrong using the ExceptionHandler. The library aims not to throw exceptions, rather it returns null and adds information on errors to the ExceptionHandler class which is in the Tweetinvi namespace. So, try checking for null on the returned object, then look at the ExceptionHandler... something like this:
if (tweets == null)
{
textBox1.Text += ExceptionHandler.GetLastException().TwitterDescription;
}
The most likely culprit is that you're not actually authenticated.
Upvotes: 4