Reputation: 1533
I'm using TweetSharp for C#, and I'm successfully able to publish tweets to twitter via this.
However, I'm trying to read the most recent tweets from the account's timeline, but I keep getting null back every time I try to get the data. The following code returns null
string consumerKey = <consumerKey>;
string consumerSecret = <consumerSecret>;
TwitterService service = new TwitterService(consumerKey, consumerSecret);
service.AuthenticateWith(consumerKey, consumerSecret);
var options = new ListTweetsOnUserTimelineOptions()
{
ScreenName = screenName,
SinceId = 0,
Count = 5
};
var currentTweets = service.ListTweetsOnUserTimeline(options);
I've tried using UserId
instead of ScreenName
, but I still get null
as a result fir currentTweets
. All the examples I can find are pointing to this method, but it doesn't work.
Any Ideas?
Upvotes: 1
Views: 522
Reputation: 7069
If you're using an older version of .NET, then you may be using TLS 1.1 under the hood to communicate with Twitter. If you are doing this, then the AuthenticateWith will fail silently, and nothing will work.
You need to add the code
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
In order to make this work.
Also you should be passing the accessToken and accessTokenSecret to AuthenticateWith, not the consumer keys, as mentioned above.
Upvotes: 3
Reputation: 787
I think your problem is the AuthenticateWith call. You appear to be passing the consumer token and secret again, but the AuthenticateWith overload that takes only two arguments expects a user token and secret. I suspect you are therefore getting an unauthorised response (not sure why you don't get an error).
I would suggest either removing the AuthenticateWith call (you've already provided the consumer token in the constructor), or changing it so you pass details for a valid user token instead of the consumer one.
You could also check the Response property on the twitter service after your call completes, and inspect the http status code/reason phrase/content etc. to see if that gives you more detail about what is going wrong.
Upvotes: 1