ASP.NET: You must provide a consumerKey

Jan 30, 2013 at 12:30 PM
Edited Jan 30, 2013 at 12:30 PM

Hi.

I'm trying to get a list of the chosen users latest feeds, using LinqToTwitter. Though i'm getting the following error:
"Parameter name: You must provide a consumerKey."

Funny thing is, i've already provided this. Here is my code:

 

SingleUserAuthorizer singleUserAuthorizer = new SingleUserAuthorizer()
            {
                Credentials = new InMemoryCredentials()
                {
                    ConsumerKey = ConfigurationManager.AppSettings["twitterconsumerKey"],
                    ConsumerSecret = ConfigurationManager.AppSettings["twitterconsumerSecret"],
                    OAuthToken = ConfigurationManager.AppSettings["twitterOAuthToken"],
                    AccessToken = ConfigurationManager.AppSettings["twitterAccessToken"]
                }
            };


            using (var twitterCtx = new TwitterContext(singleUserAuthorizer, "https://api.twitter.com/1/", "https://search.twitter.com/"))
            {

                var users =
                    (from tweet in twitterCtx.DirectMessage
                     where tweet.Type == DirectMessageType.SentTo select tweet).ToList();
             }

 Anyone got a suggestion or two? Thanks.

Coordinator
Jan 30, 2013 at 12:40 PM

Hi,

AppSettings["keyName"] specifies a key/value pair in the <appSettings /> element of your config file - there are examples on the Samples page, downloadable source code, and a separate download for Console demos. You might want to verify that Credentials is populated by setting a breakpoint and examining singleUserAuthorizer.

Also, don't include the URLs when instantiating TwitterContext. Those URLs refer to Twitter API v1.0, but LINQ to Tw itter is now on Twitter API v1.1.

@JoeMayo

Feb 1, 2013 at 8:27 AM
Edited Feb 1, 2013 at 8:29 AM
I must have been really tired or totally blind that day. I've already been working a lot with AppSettings.config.

Thanks for waking me up JoeMayo. :D.

I managed to create a functioning page now with a Twitter feed list. :)
Jul 19, 2013 at 5:37 AM
Hi

So confused. Which is what version ?

(1)
SingleUserAuthorizer singleUserAuthorizer = new SingleUserAuthorizer()
            {
                Credentials = new InMemoryCredentials()
                {
                    ConsumerKey = ConfigurationManager.AppSettings["twitterconsumerKey"],
                    ConsumerSecret = ConfigurationManager.AppSettings["twitterconsumerSecret"],
                    OAuthToken = ConfigurationManager.AppSettings["twitterOAuthToken"],
                    AccessToken = ConfigurationManager.AppSettings["twitterAccessToken"]
                }
            };
(2)
var auth = new SingleUserAuthorizer
        {
            Credentials = new SingleUserInMemoryCredentials
            {
                ConsumerKey = ConfigurationManager.AppSettings["twitterConsumerKey"],
                ConsumerSecret = ConfigurationManager.AppSettings["twitterConsumerSecret"],
                TwitterAccessToken = ConfigurationManager.AppSettings["twitterAccessToken"],
                TwitterAccessTokenSecret = ConfigurationManager.AppSettings["twitterAccessTokenSecret"]
            }
        };
Coordinator
Jul 19, 2013 at 6:21 AM
Hi,

For SingleUserAuthorizer, go with #2.

Some background:

In all cases, you need to provide ConsumerKey and ConsumerSecret, which identify your app. The other two keys depend on authorizer.

If you watch the OAuth communication with Fiddler during the PinAuthorizer or WebAuthorizer flow, you'll see that Twitter returns an OAuthToken (oauth_token) and AccessToken (access_token). That's what Twitter API calls them, so LINQ to Twitter uses the same names. This has been true since Twitter has been doing OAuth.

After Twitter's initial introduction of OAuth, they came up with another process called Single User Authorization, which LINQ to Twitter supports via the SingleUserAuthorizer. The naming convention of OAuthToken and AccessToken was already in place at that time, so I continued using it. I'm not sure if Twitter's original implementation of Single User Authorization adopted the same names. My thoughts are that it did, which I continued to follow. For some reason, Twitter decided to name those two tokens as AccessToken and AccessTokenSecret, which matched what I called OAuthToken and AccessToken, respectively. Initially, I didn't change the name because just putting the right tokens in the right place worked fine and it was documented. However, after some feedback, I created the SingleUserInMemoryCredentials, which introduced the TwitterAccessToken and TwitterAccessTokenSecret to match Twitter's naming convention for the tokens that you find on your Twitter application page.

Twitter API has a history of changing dramatically and without notice. These days things are a whole lot more stable. However, you'll still see mismatches where the Twitter API has changed, but LINQ to Twitter has the original naming and it's mostly for historical reasons and a reluctance to break developer's code more than I need to. To help with this, all of the LINQ to Twitter APIs have a link to where they match the Twitter API. I've also recently published a Twitter API Map so folks can review the Twitter API documentation and then find where LINQ to Twitter provides support.

Anyway, LINQ to Twitter continues to evolve and hopefully I can gradually clear up these types of anomalies to make the API even easier to use.

@JoeMayo
Aug 2, 2013 at 9:12 PM
Thank you Joe.
The latest upgrade has helped.
Great work!
Cheers!
Wasim