.netresttwitter-oauthrestful-authenticationtweetsharp

Twitter API [1.1] Authentication Request —


Need good amount of help on this one. Basically in my application, I am required to access twitter api, fetch the top 50 posts as per a specific search tag and display them. Naturally the agenda of authentication comes in. Now this is giving me severe trouble. My code doesn't work seemingly because of - Bad authentication data [215]. I've used the TweetSharp package to form my code.

I'll post it here --

    public class TweetHelper
    public class TweetHelper
    {
        public static string _consumerKey = "whatever";
        public static string _consumerSecret = "whatever";
        public static string _accessToken = "whatever";
        public static string _accessTokenSecret = "whatever";

public static List<TwitterStatus> GetTweetList1()
    {
        TwitterService twitterService = new TwitterService(_consumerKey, _consumerSecret);
        int tweetcount = 1;

----> var tweets_search = twitterService.Search(new SearchOptions { Q = "#ClimateChange", Resulttype = TwitterSearchResultType.Popular, Count = 50 }); ----> twitterService.AuthenticateWith(_accessToken, _accessTokenSecret);

        List<TwitterStatus> resultList = new List<TwitterStatus>(tweets_search.Statuses);
        foreach (var tweet in tweets_search.Statuses)
        {
            try
            {
                tweet.User.ScreenName.ToString();
                tweet.User.Name.ToString();
                tweet.Text.ToString();
                tweet.RetweetCount.ToString();
                tweet.User.FavouritesCount.ToString();
                tweet.User.ProfileImageUrl.ToString();
                tweet.CreatedDate.ToString();
                ("https://twitter.com/intent/retweet?tweet_id=" + tweet.Id).ToString();
                ("https://twitter.com/intent/tweet?in_reply_to=" + tweet.Id).ToString();
                ("https://twitter.com/intent/favorite?tweet_id=" + tweet.Id).ToString();

                tweetcount++;
            }
            catch (Exception exp)
            {
                throw exp;
            }
        }
        return resultList;


    }

}

I know 1.0 API version has been deprecated by twitter. And 2.0 hasn't arrived. So it has to be 1.1. As you can see, those two are the problem lines, where the error is happening. What am I doing wrong? Or what piece of information from the API versions is it that I'm wrongly approaching? It can't be that all those keys and tokens, secrets etc are wrong. I copied them correctly all right, while creating my app.One more thing is that, I'm trying this from my dev. environment on my local machine; where I did an edit of the windows host file to make my application run from that specific IP address and behave like a definite url. I also used this, while filling in the details of the website, domain etc. fields during creating the twitter app.

I used rest client postman and all that to cross check the api request thing. And yes, it does return 215 code Bad AUthentication Data. Someone told me, it could happen due to fact that clock on my computer is not time synced with internet. So I did that too just to make sure. Still nothing. I'm in a gloom literally. Kindly help me on this issue. I am finding it tough to get past. Thanks in advance,


Solution

  • You appear to be calling AuthenticateWith after making the Search call. That won't work, if you want to search as a given user you need to call AuthenticateWith first.

    Also are you using a current version of TweetSharp? The original/official nugget package is no longer supported and has known bugs, especially around long integer handling.