svnno****@sourc*****
svnno****@sourc*****
2010年 12月 10日 (金) 17:40:40 JST
Revision: 1195 http://sourceforge.jp/projects/tween/svn/view?view=rev&revision=1195 Author: kiri_feather Date: 2010-12-10 17:40:40 +0900 (Fri, 10 Dec 2010) Log Message: ----------- 認証エラーになったら、サーバー時刻と現在時刻をメッセージとして戻すように。 発言投稿時に認証エラーだと、リトライでエラーがクリアされてしまうバグ修正。 Modified Paths: -------------- trunk/Tween/Connection/HttpConnectionBasic.vb trunk/Tween/Connection/HttpConnectionOAuth.vb trunk/Tween/Connection/HttpTwitter.vb trunk/Tween/Connection/IHttpConnection.vb trunk/Tween/Tween.vb trunk/Tween/Twitter.vb -------------- next part -------------- Modified: trunk/Tween/Connection/HttpConnectionBasic.vb =================================================================== --- trunk/Tween/Connection/HttpConnectionBasic.vb 2010-12-10 05:59:22 UTC (rev 1194) +++ trunk/Tween/Connection/HttpConnectionBasic.vb 2010-12-10 08:40:40 UTC (rev 1195) @@ -193,7 +193,7 @@ '''<param name="url">認証先のURL</param> '''<param name="userName">認証で使用するユーザー名</param> '''<param name="password">認証で使用するパスワード</param> - Public Function Authenticate(ByVal url As Uri, ByVal username As String, ByVal password As String) As HttpStatusCode Implements IHttpConnection.Authenticate + Public Function Authenticate(ByVal url As Uri, ByVal username As String, ByVal password As String, ByRef content As String) As HttpStatusCode Implements IHttpConnection.Authenticate 'urlは認証必要なGETメソッドとする Dim orgCre As String = Me.credential Me.credential = "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(username + ":" + password)) Modified: trunk/Tween/Connection/HttpConnectionOAuth.vb =================================================================== --- trunk/Tween/Connection/HttpConnectionOAuth.vb 2010-12-10 05:59:22 UTC (rev 1194) +++ trunk/Tween/Connection/HttpConnectionOAuth.vb 2010-12-10 08:40:40 UTC (rev 1195) @@ -245,7 +245,7 @@ '''<param name="username">認証用ユーザー名</param> '''<param name="password">認証用パスワード</param> '''<returns>取得結果真偽値</returns> - Public Function AuthenticateXAuth(ByVal accessTokenUrl As Uri, ByVal username As String, ByVal password As String) As HttpStatusCode Implements IHttpConnection.Authenticate + Public Function AuthenticateXAuth(ByVal accessTokenUrl As Uri, ByVal username As String, ByVal password As String, ByRef content As String) As HttpStatusCode Implements IHttpConnection.Authenticate 'ユーザー・パスワードチェック If String.IsNullOrEmpty(username) OrElse String.IsNullOrEmpty(password) Then Throw New Exception("Sequence error.(username or password is blank)") @@ -257,7 +257,6 @@ parameter.Add("x_auth_password", password) 'アクセストークン取得 - Dim content As String = "" Dim httpCode As HttpStatusCode = GetOAuthToken(accessTokenUrl, "", "", parameter, content) If httpCode <> HttpStatusCode.OK Then Return httpCode Dim accessTokenData As NameValueCollection = ParseQueryString(content) @@ -335,7 +334,11 @@ 'OAuth関連情報をHTTPリクエストに追加 AppendOAuthInfo(webReq, query, requestToken, "") 'HTTP応答取得 - Return GetResponse(webReq, content, Nothing, False) + Dim header As New Dictionary(Of String, String) From {{"Date", ""}} + Dim responceCode As HttpStatusCode = GetResponse(webReq, content, header, False) + If responceCode = HttpStatusCode.OK Then Return responceCode + If Not String.IsNullOrEmpty(header("Date")) Then content += Environment.NewLine + "Check the Date & Time of this computer." + Environment.NewLine + "Server:" + CDate(header("Date")).ToString + " PC:" + Now.ToString + Return responceCode End Function #End Region Modified: trunk/Tween/Connection/HttpTwitter.vb =================================================================== --- trunk/Tween/Connection/HttpTwitter.vb 2010-12-10 05:59:22 UTC (rev 1194) +++ trunk/Tween/Connection/HttpTwitter.vb 2010-12-10 08:40:40 UTC (rev 1195) @@ -115,11 +115,11 @@ End Get End Property - Public Function AuthUserAndPass(ByVal username As String, ByVal password As String) As HttpStatusCode + Public Function AuthUserAndPass(ByVal username As String, ByVal password As String, ByRef content As String) As HttpStatusCode If connectionType = AuthMethod.Basic Then - Return httpCon.Authenticate(CreateTwitterUri("/1/account/verify_credentials.json"), username, password) + Return httpCon.Authenticate(CreateTwitterUri("/1/account/verify_credentials.json"), username, password, content) Else - Return httpCon.Authenticate(New Uri(AccessTokenUrlXAuth), username, password) + Return httpCon.Authenticate(New Uri(AccessTokenUrlXAuth), username, password, content) End If End Function Modified: trunk/Tween/Connection/IHttpConnection.vb =================================================================== --- trunk/Tween/Connection/IHttpConnection.vb 2010-12-10 05:59:22 UTC (rev 1194) +++ trunk/Tween/Connection/IHttpConnection.vb 2010-12-10 08:40:40 UTC (rev 1195) @@ -25,7 +25,7 @@ Sub RequestAbort() - Function Authenticate(ByVal url As Uri, ByVal username As String, ByVal password As String) As HttpStatusCode + Function Authenticate(ByVal url As Uri, ByVal username As String, ByVal password As String, ByRef content As String) As HttpStatusCode ReadOnly Property AuthUsername() As String ''' <summary> Modified: trunk/Tween/Tween.vb =================================================================== --- trunk/Tween/Tween.vb 2010-12-10 05:59:22 UTC (rev 1194) +++ trunk/Tween/Tween.vb 2010-12-10 08:40:40 UTC (rev 1195) @@ -1996,7 +1996,8 @@ ret.StartsWith("Warn:") OrElse _ ret = "Err:Status is a duplicate." OrElse _ args.status.status.StartsWith("D", StringComparison.OrdinalIgnoreCase) OrElse _ - args.status.status.StartsWith("DM", StringComparison.OrdinalIgnoreCase) Then + args.status.status.StartsWith("DM", StringComparison.OrdinalIgnoreCase) OrElse _ + Twitter.AccountState <> ACCOUNT_STATE.Valid Then Exit For End If Next Modified: trunk/Tween/Twitter.vb =================================================================== --- trunk/Tween/Twitter.vb 2010-12-10 05:59:22 UTC (rev 1194) +++ trunk/Tween/Twitter.vb 2010-12-10 08:40:40 UTC (rev 1195) @@ -87,7 +87,7 @@ TwitterApiInfo.Initialize() Try - res = twCon.AuthUserAndPass(username, password) + res = twCon.AuthUserAndPass(username, password, content) Catch ex As Exception Return "Err:" + ex.Message End Try @@ -102,7 +102,7 @@ Twitter.AccountState = ACCOUNT_STATE.Invalid Dim errMsg As String = GetErrorMessageJson(content) If String.IsNullOrEmpty(errMsg) Then - Return "Check your Username/Password." + Return "Check your Username/Password." + Environment.NewLine + content Else Return "Auth error:" + errMsg End If