Cannot post Tweets with Linq to Twitter using saved Oauth credentials
I have no problems using the Linq to Twitter WebAuthorizer to post Tweets
to Twitter if my end-users are directed to Twitter's Oauth page and
returned to our site. Using WebAuthorizer in this manner works great.
However, if I try to store the end-user's Oauth credentials and use them
to Tweet, I get a 401 Unauthorized error:
LinqToTwitter.TwitterQueryException: Invalid or expired token --->
System.Net.WebException: The remote server returned an error: (401)
Unauthorized. at LinqToTwitter.TwitterExecute.PostToTwitter[T](String url,
IDictionary2 postData, Func2 getResult) --- End of inner exception stack
trace --- at LinqToTwitter.TwitterExecute.PostToTwitter[T](String url,
IDictionary2 postData, Func2 getResult) at
LinqToTwitter.StatusExtensions.UpdateStatus(TwitterContext ctx, String
status, Decimal latitude, Decimal longitude, String placeID, Boolean
displayCoordinates, String inReplyToStatusID, Boolean trimUser, Action`1
callback) at LinqToTwitter.StatusExtensions.UpdateStatus(TwitterContext
ctx, String status) at
External_WCPages_v12_Test_TwitterTest.StoredCredentialsSingleUserAuthorizer()
in
C:\TFS\SC\Weblink_Connect-Development\CWT\External\WCPages\v12\Test\TwitterTest.aspx.vb:line
177 at External_WCPages_v12_Test_TwitterTest.Page_Load(Object sender,
EventArgs e) in
C:\TFS\SC\Weblink_Connect-Development\CWT\External\WCPages\v12\Test\TwitterTest.aspx.vb:line
65
I am including the primary functions which handle the Linq to Twitter
requests. Please help, am I doing something wrong? I have tried releases
2.106, 2.107, 2.108 and the latest changesets as of 9/19/2013.
Private Sub BeginWebAuthorizer()
'Comment: Triggered on PostBack
mobj_WebAuthorizer = New WebAuthorizer
Dim objCredentials As IOAuthCredentials = New InMemoryCredentials()
objCredentials.ConsumerKey = Me.ConsumerKey
objCredentials.ConsumerSecret = Me.ConsumerSecret
mobj_WebAuthorizer.Credentials = objCredentials
mobj_WebAuthorizer.PerformRedirect = Sub(authUrl)
Response.Redirect(authUrl)
End Sub
mobj_WebAuthorizer.BeginAuthorization(Request.Url)
End Sub
Private Sub CompleteWebAuthorizer()
'Comment: Triggered on return from the Twitter authorization page
Dim objCredentials As IOAuthCredentials = New
SingleUserInMemoryCredentials
objCredentials.ConsumerKey = Me.ConsumerKey
objCredentials.ConsumerSecret = Me.ConsumerSecret
mobj_WebAuthorizer = New WebAuthorizer
mobj_WebAuthorizer.Credentials = objCredentials
Call mobj_WebAuthorizer.CompleteAuthorization(Request.Url)
mobj_TwitterContext = New TwitterContext(mobj_WebAuthorizer)
'Success: This posts a Tweet
mobj_TwitterContext.UpdateStatus("Test Tweet using LinqToTwitter
WebAuthorizer ( not using stored credentials ) : " &
Date.Now.Millisecond.ToString)
End Sub
Private Sub StoredCredentialsWebAuthorizer()
'Comment: Triggered on PostBack
Dim objCredentials As IOAuthCredentials = New InMemoryCredentials
'For Testing: Dim objCredentials As IOAuthCredentials = New
SingleUserInMemoryCredentials
'For Testing: Dim objCredentials As IOAuthCredentials = New
SessionStateCredentials
objCredentials.ConsumerKey = Me.ConsumerKey
objCredentials.ConsumerSecret = Me.ConsumerSecret
objCredentials.AccessToken = Me.SavedToken
objCredentials.OAuthToken = Me.SavedTokenSecret
mobj_WebAuthorizer = New WebAuthorizer
mobj_WebAuthorizer.Credentials = objCredentials
'For Testing: Call
mobj_WebAuthorizer.CompleteAuthorization(Request.Url)
mobj_TwitterContext = New TwitterContext(mobj_WebAuthorizer)
'BUG: SingleUserAuthorizer doesn't seem to work with the saved
credentials from database
mobj_TwitterContext.UpdateStatus("Test Tweet using LinqToTwitter
WebAuthorizer ( using stored credentials ) : " &
Date.Now.Millisecond.ToString)
End Sub
No comments:
Post a Comment