Getting started...

Apr 19, 2011 at 4:55 PM

Hello!

I am new to linqtotwitter and unable to find any appropriate point, from where to start? I just need a sample code for authentication using silverlight.

 

Regards,

Taha!

Coordinator
Apr 19, 2011 at 5:17 PM

Hi Taha,

In the downloadable source code, I have a Silverlight example.  There's code to show how to use both OOB and Web.

Joe

Apr 19, 2011 at 5:29 PM

Joe, thanks for your quick response!

I am using the following code:

var auth = new SilverlightAuthorizer
            {
                Credentials = new InMemoryCredentials
                {
                    ConsumerKey = "",
                    ConsumerSecret = ""
                },
                PerformRedirect = authUrl =>
                    Dispatcher.BeginInvoke(() => HtmlPage.Window.Navigate(new Uri(authUrl)))
            };

            Uri url = HtmlPage.Document.DocumentUri;

            auth.CompleteAuthorize(url, resp =>
                Dispatcher.BeginInvoke(() =>
                {
                    switch (resp.Status)
                    {
                        case TwitterErrorStatus.Success:
                            UpdatePanel.Visibility = Visibility.Visible;
                            TweetTextBox.Text = "Silverlight Web Test, " + DateTime.Now.ToString() + " #linqtotwitter";
                            break;
                        case TwitterErrorStatus.TwitterApiError:
                        case TwitterErrorStatus.RequestProcessingException:
                            MessageBox.Show(
                                resp.Error.ToString(),
                                resp.Message,
                                MessageBoxButton.OK);
                            break;
                    }
                }));

            if (!auth.IsAuthorized && !auth.IsAuthorizing)
            {
                auth.BeginAuthorize(url, resp =>
                    Dispatcher.BeginInvoke(() =>
                    {
                        switch (resp.Status)
                        {
                            case TwitterErrorStatus.Success:
                                break;
                            case TwitterErrorStatus.TwitterApiError:
                            case TwitterErrorStatus.RequestProcessingException:
                                MessageBox.Show(
                                    resp.Error.ToString(),
                                    resp.Message,
                                    MessageBoxButton.OK);
                                break;
                        }
                    }));
            }

            m_twitterCtx = new TwitterContext(auth);

 

But got following error:

The remote server returned an error: not found

Coordinator
Apr 19, 2011 at 6:01 PM

A couple things to check:

1. Are you populating your credentials with your Twitter ConsumerKey and ConsumerSecret?  BTW, if you are, it's good that you don't show them in the forum where everyone can see.  If not, visit dev.Twitter.com, create an App, give it full permissions and then populate credentials.

2. Where is the error occurring?

Joe

Apr 19, 2011 at 6:13 PM

Yes, I have already registered my app. Error is occurring on auth.BeginAuthorize call.