I am using VB.Net 3.5 and VS 2010. I have a web app that needs to send
Tweets when information is made available, such as news updates, new
members, etc. But I seem to be having a problem with the Trust level
when I publish the application to Rackspace,my web host. I have talked
to them about the trust issue but they are unwilling to change the
level to Full trust for my app. Anyway here is what I have done so

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" value="YOUR APPS OAUTHTOKEN SECRET 
KEY" /

If 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" and others do not allow
this trust level automatically!

However if the trust level is less than "Full" on your host you will
likely receive the error message: "Twitter Returned: Request for the
permission of type 'System.Security.Permissions.SecurityPermission,
mscorlib, Version=, Culture=neutral,
PublicKeyToken=b77a5c561934e089' failed."

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