My development environment is MS Visual Studio 2010, using VB.NET. All
I
need to do is post a Tweet for some of the identified status changes
within
my web application. I don't need user verification as the app is
designed to
automatically post the status change Tweet whenever it occurs.
I added all 4 required values, ConsumerKey, ConsumerSecret,
OAuthToken, and
OAuthTokenSecret to the web.config file in the "appSettings" section
of the
"configuration" section.
<appSettings>
<!-- Twitter and BitLy access keys -->
<add key="ConsumerKey" value="MYCONSUMERKEY"
/>
<add key="ConsumerSecret"
value="MYCONSUMERSECRETKEY" />
<add key="OAuthToken"
value="MYAPPSOAUTHTOKENKEY" />
<add key="OAuthTokenSecret"
value="MYAPPSOAUTHTOKENSECRETKEY" />
</appSettings>
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 click 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
application 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!
Now that you have all the keys, put them in the "appSettings" section
of the
web.config file.
I add "Dim twConn As New TwitterVB2.TwitterAPI" at the top of the code
behind web 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 =
System.Configuration.ConfigurationManager.AppSettings("ConsumerKey")
Dim twitterSecret As String =
System.Configuration.ConfigurationManager.AppSettings("ConsumerSecret")
Dim twitterOAuthToken As String =
System.Configuration.ConfigurationManager.AppSettings("OAuthToken")
Dim twitterOAuthTokenSecret As String =
System.Configuration.ConfigurationManager.AppSettings("OAuthTokenSecret")
Try
twConn.AuthenticateWith(twitterKey, twitterSecret,
twitterOAuthToken, twitterOAuthTokenSecret)
twConn.Update(Trim(Tweet))
Catch ex As Exception
lblError.Text = "Twitter Returned: " & ex.Message
End Try
End Sub
This code works great on my local development, an environment that
allows
"Full" trust level. However it appears when I publish my application
to my
host, Rackspace.com which uses an environment of "Cloud Hosting" , the
Trust
Level is less than "Full" and I get an error. "Twitter Returned:
Request
for the permission of type
'System.Security.Permissions.SecurityPermission,
mscorlib, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089'
failed."
Can you tell me what I am doing wrong, and what I need to do to fix
the
problem? Thanks.

-- 
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: 
http://groups.google.com/group/twitter-development-talk

Reply via email to