>From my web site, when certain events occur, such as a visitor
registers, a news event happens, etc, I need to post the message
"Tweet" on Twitter.com. I have written the web application in VB.NET
3.5 using Visual Studio 2008.

I added all 4 required values, ConsumerKey, ConsumerSecret,
OAuthToken, and OAuthTokenSecret to the web.config file in the
"appSettings" section of the "configuration" section.

                <!-- Twitter and BitLy access keys -->
                <add key="ConsumerKey" value="YOUR_CONSUMER_KEY" />
                <add key="ConsumerSecret" value="YOUR_CONSUMER_SECRET_KEY" />
                <add key="OAuthToken" value="YOUR_APPS_OAUTHTOKEN_KEY" />
                <add key="OAuthTokenSecret" 
I found that by going to twitter.com and signing into the account that
is using the application, then go to the "Settings" page, go to the
bottom of the page and click on the "API" menu option. Once the API
page appears you will clik on the button "2", Register An App. On the
right side on the new page, you will see a button "View Your
Applications." If you have previously registered your app, click this
button, If not fill out the appliction for a new app. Now at the View
your Applications page, select the app you want to get the
authorization keys for where is says "Edit Details".

Now click on the button to the right that says, "Application Detail."
Here you will find your Consumer Key and your Consumer Secret Key. On
the right side of this page you will see the menu option "My Access
Token", click it and you will find your oauth_token and your
oauth_token_secret keys!

Not that you have all the keys, put them in the "appSettings" section
of the web.config file.

Add "Dim twConn As New TwitterVB2.TwitterAPI" at the top of the page.

I then created a subroutine where I pass in the Tweet:

    Public Sub PostOnTwitter(ByVal Tweet As String)
         'Retrieve Keys from web.config
        Dim twitterKey As String =
        Dim twitterSecret As String =
        Dim twitterOAuthToken As String =
        Dim twitterOAuthTokenSecret As String =

            twConn.AuthenticateWith(twitterKey, twitterSecret,
twitterOAuthToken, twitterOAuthTokenSecret)
        Catch ex As Exception
            lblError.Text = "Twitter Returned: " & ex.Message
        End Try
    End Sub

This code works great in an enviornment that allows at least a
"Medium" trust level. However it appears that many of the "new"
hosting envrionments such as "Cloud Hosting", "Web Farm", and others
do not allow this trust level automatically!However if the trust level
is less than "Medium" on your host you will likely receive the error
"Twitter Returned: Request for the permission of type
'System.Security.Permissions.SecurityPermission, mscorlib,
Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'

I am unfamiliar with how to create altered Trust Level in the
web.config fiel. If anyone has found a fix for this "Trust Level"
issue please post it!

Twitter developer documentation and resources: http://dev.twitter.com/doc
API updates via Twitter: http://twitter.com/twitterapi
Issues/Enhancements Tracker: http://code.google.com/p/twitter-api/issues/list
Change your membership to this group: 

Reply via email to