İzlediğim videodaki kodun aynısını yazdım ama bu hatayla karşılaşıyorum. Anlamı nedir?
Hata mesajı:
JsonSerializationException was unhandled
An unhandled exception of type 'Newtonsoft.Json.JsonSerializationException' occurred in Newtonsoft.Json.dll
Additional information: Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'TweetSharp.TwitterStatus' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.
Path '', line 1, position 1.
Kod:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TweetSharp;
namespace TwitterApi
{
public partial class Form1 : Form
{
TwitterService servis;
public Form1()
{
InitializeComponent();
servis = new TwitterService("Consumer Key", "Consumer Secret", "Access Token", "Access Token Secret");
}
private void button1_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
var gelen = servis.ListTweetsOnHomeTimeline(new ListTweetsOnHomeTimelineOptions() { Count = 20 });
foreach (var tweet in gelen)
{
listBox1.Items.Add(tweet.Text);
}
}
}
}
Toplam 2 cevap
Tweetsharp yerine Tweetinvi kütüphanesini kullansan daha doğru olur. Kontrol ettim, Tweetsharp 2013 yılından beri güncellenmiyor. Bu sana sıkıntılar yaşatabilir.
Tweetinvi kütüphanesini nuget üzerinden yükleyebilirsin. Detaylı bilgi buradan alabilirsin: https://github.com/linvi/tweetinvi/wiki/Introduction
Yapmak istediğin işlem için kod:
Auth.SetUserCredentials("CONSUMER_KEY", "CONSUMER_SECRET", "ACCESS_TOKEN", "ACCESS_TOKEN_SECRET");
var tweets = Timeline.GetHomeTimeline(){ };
foreach (var t in tweets)
{
listBox1.Items.Add(t.FullText);
}Visual Studio 2015 üzerinde test ettim, sorunsuz çalışıyor.
İzlediğim videolarda Visual Studio 2013 kullanılıyor galiba.
Visual Studio 2013 Community İndirme Linki Nedir?