svnno****@sourc*****
svnno****@sourc*****
2010年 12月 10日 (金) 03:27:03 JST
Revision: 1192 http://sourceforge.jp/projects/tween/svn/view?view=rev&revision=1192 Author: kiri_feather Date: 2010-12-10 03:27:03 +0900 (Fri, 10 Dec 2010) Log Message: ----------- 認証のjson化 投稿、DM投稿のjson化 ユーザー情報取得のjson化 データモデルの発言数Integerへ。UserにもStatus持てるように。 DateTimeParseをMyCommonへ移動 ShowUserInfo関連をjson化 Modified Paths: -------------- trunk/Tween/Connection/HttpTwitter.vb trunk/Tween/DataModel.vb trunk/Tween/MyCommon.vb trunk/Tween/ShowUserInfo.vb trunk/Tween/Tween.vb trunk/Tween/Twitter.vb -------------- next part -------------- Modified: trunk/Tween/Connection/HttpTwitter.vb =================================================================== --- trunk/Tween/Connection/HttpTwitter.vb 2010-12-09 14:22:14 UTC (rev 1191) +++ trunk/Tween/Connection/HttpTwitter.vb 2010-12-09 18:27:03 UTC (rev 1192) @@ -117,7 +117,7 @@ Public Function AuthUserAndPass(ByVal username As String, ByVal password As String) As HttpStatusCode If connectionType = AuthMethod.Basic Then - Return httpCon.Authenticate(CreateTwitterUri("/1/account/verify_credentials.xml"), username, password) + Return httpCon.Authenticate(CreateTwitterUri("/1/account/verify_credentials.json"), username, password) Else Return httpCon.Authenticate(New Uri(AccessTokenUrlXAuth), username, password) End If @@ -148,7 +148,7 @@ If replyToId > 0 Then param.Add("in_reply_to_status_id", replyToId.ToString) Return httpCon.GetContent(PostMethod, _ - CreateTwitterUri("/1/statuses/update.xml"), _ + CreateTwitterUri("/1/statuses/update.json"), _ param, _ content, _ Nothing, _ @@ -170,7 +170,7 @@ param.Add("screen_name", sendto) Return httpCon.GetContent(PostMethod, _ - CreateTwitterUri("/1/direct_messages/new.xml"), _ + CreateTwitterUri("/1/direct_messages/new.json"), _ param, _ content, _ Nothing, _ @@ -199,7 +199,7 @@ Dim param As New Dictionary(Of String, String) param.Add("screen_name", screenName) Return httpCon.GetContent(GetMethod, _ - CreateTwitterUri("/1/users/show.xml"), _ + CreateTwitterUri("/1/users/show.json"), _ param, _ content, _ TwitterApiInfo.HttpHeaders, _ Modified: trunk/Tween/DataModel.vb =================================================================== --- trunk/Tween/DataModel.vb 2010-12-09 14:22:14 UTC (rev 1191) +++ trunk/Tween/DataModel.vb 2010-12-09 18:27:03 UTC (rev 1192) @@ -38,7 +38,7 @@ <DataContract()> _ Public Class User - <DataMember(Name:="statuses_count")> Public StatusesCount As Int64 + <DataMember(Name:="statuses_count")> Public StatusesCount As Integer <DataMember(Name:="profile_sidebar_fill_color")> Public ProfileSidebarFillColor As String <DataMember(Name:="show_all_inline_media")> Public ShowAllInlineMedia As Boolean <DataMember(Name:="profile_use_background_image")> Public ProfileUseBackgroundImage As Boolean @@ -72,6 +72,7 @@ <DataMember(Name:="profile_background_tile")> Public ProfileBackgroundTile As Boolean <DataMember(Name:="utc_offset")> Public UtcOffset As String <DataMember(Name:="place", IsRequired:=False)> Public Place As Place + <DataMember(Name:="status", IsRequired:=False)> Public Status As Status End Class <DataContract()> _ Modified: trunk/Tween/MyCommon.vb =================================================================== --- trunk/Tween/MyCommon.vb 2010-12-09 14:22:14 UTC (rev 1191) +++ trunk/Tween/MyCommon.vb 2010-12-09 18:27:03 UTC (rev 1192) @@ -570,4 +570,24 @@ If img IsNot Nothing Then img.Dispose() End Try End Function + + Public Function DateTimeParse(ByVal input As String) As Date + Dim rslt As Date + Dim format() As String = { + "ddd MMM dd HH:mm:ss zzzz yyyy" + } + For Each fmt As String In format + If DateTime.TryParseExact(input, _ + fmt, _ + System.Globalization.DateTimeFormatInfo.InvariantInfo, _ + System.Globalization.DateTimeStyles.None, _ + rslt) Then + Return rslt + Else + Continue For + End If + Next + TraceOut("Parse Error(DateTimeFormat) : " + input) + Return New Date + End Function End Module \ No newline at end of file Modified: trunk/Tween/ShowUserInfo.vb =================================================================== --- trunk/Tween/ShowUserInfo.vb 2010-12-09 14:22:14 UTC (rev 1191) +++ trunk/Tween/ShowUserInfo.vb 2010-12-09 18:27:03 UTC (rev 1192) @@ -29,7 +29,7 @@ Public Class ShowUserInfo - Private userInfoXml As String = "" + Private userInfo As TwitterDataModel.User = Nothing Private _info As New UserInfo Private icondata As Image = Nothing Private atlist As New Generic.List(Of String) @@ -63,57 +63,39 @@ ToolTip1.SetToolTip(LinkLabelFav, Favorites) End Sub - Private Function AnalizeUserInfo(ByVal xmlData As String) As Boolean - If xmlData Is Nothing Then Return False - Dim xdoc As New XmlDocument - Try - xdoc.LoadXml(xmlData) - Dim nd As String = "/user" + Private Function AnalizeUserInfo(ByVal user As TwitterDataModel.User) As Boolean + If user Is Nothing Then Return False - If xdoc.SelectSingleNode(nd) Is Nothing Then - nd = "/status/user" - End If - - _info.Id = Int64.Parse(xdoc.SelectSingleNode(nd + "/id").InnerText) - _info.Name = xdoc.SelectSingleNode(nd + "/name").InnerText - _info.ScreenName = xdoc.SelectSingleNode(nd + "/screen_name").InnerText - _info.Location = xdoc.SelectSingleNode(nd + "/location").InnerText - _info.Description = xdoc.SelectSingleNode(nd + "/description").InnerText - _info.ImageUrl = New Uri(xdoc.SelectSingleNode(nd + "/profile_image_url").InnerText) - - _info.Url = xdoc.SelectSingleNode(nd + "/url").InnerText - - _info.Protect = Boolean.Parse(xdoc.SelectSingleNode(nd + "/protected").InnerText) - _info.FriendsCount = Integer.Parse(xdoc.SelectSingleNode(nd + "/friends_count").InnerText) - _info.FollowersCount = Integer.Parse(xdoc.SelectSingleNode(nd + "/followers_count").InnerText) - _info.FavoriteCount = Integer.Parse(xdoc.SelectSingleNode(nd + "/favourites_count").InnerText) - _info.CreatedAt = DateTime.ParseExact(xdoc.SelectSingleNode(nd + "/created_at").InnerText, "ddd MMM dd HH:mm:ss zzzz yyyy", System.Globalization.DateTimeFormatInfo.InvariantInfo, System.Globalization.DateTimeStyles.None) - _info.StatusesCount = Integer.Parse(xdoc.SelectSingleNode(nd + "/statuses_count").InnerText) - _info.Verified = Boolean.Parse(xdoc.SelectSingleNode(nd + "/verified").InnerText) - - ' 最終発言が取れないことがある + Try + _info.Id = user.Id + _info.Name = user.Name + _info.ScreenName = user.ScreenName + _info.Location = user.Location + _info.Description = user.Description + _info.ImageUrl = New Uri(user.ProfileImageUrl) + _info.Url = user.Url + _info.Protect = user.Protected + _info.FriendsCount = user.FriendsCount + _info.FollowersCount = user.FollowersCount + _info.FavoriteCount = user.FavouritesCount + _info.CreatedAt = DateTimeParse(user.CreatedAt) + _info.StatusesCount = user.StatusesCount + _info.Verified = user.Verified Try - If nd = "/user" Then - _info.RecentPost = xdoc.SelectSingleNode(nd + "/status/text").InnerText - _info.PostCreatedAt = DateTime.ParseExact(xdoc.SelectSingleNode(nd + "/status/created_at").InnerText, "ddd MMM dd HH:mm:ss zzzz yyyy", System.Globalization.DateTimeFormatInfo.InvariantInfo, System.Globalization.DateTimeStyles.None) - _info.PostSource = xdoc.SelectSingleNode(nd + "/status/source").InnerText - Else - _info.RecentPost = xdoc.SelectSingleNode("/status/text").InnerText - _info.PostCreatedAt = DateTime.ParseExact(xdoc.SelectSingleNode("/status/created_at").InnerText, "ddd MMM dd HH:mm:ss zzzz yyyy", System.Globalization.DateTimeFormatInfo.InvariantInfo, System.Globalization.DateTimeStyles.None) - _info.PostSource = xdoc.SelectSingleNode("/status/source").InnerText - End If - If Not _info.PostSource.Contains("</a>") Then - _info.PostSource += "</a>" - End If + _info.RecentPost = user.Status.Text + _info.PostCreatedAt = DateTimeParse(user.Status.CreatedAt) + _info.PostSource = user.Status.Source Catch ex As Exception _info.RecentPost = Nothing _info.PostCreatedAt = Nothing _info.PostSource = Nothing End Try + If Not _info.PostSource.Contains("</a>") Then + _info.PostSource += "</a>" + End If Catch ex As Exception Return False End Try - Return True End Function @@ -141,7 +123,7 @@ Private Sub ShowUserInfo_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load MyOwner = DirectCast(Me.Owner, TweenMain) - If Not AnalizeUserInfo(userInfoXml) Then + If Not AnalizeUserInfo(userInfo) Then MessageBox.Show(My.Resources.ShowUserInfo1) Me.Close() Exit Sub @@ -210,9 +192,9 @@ Me.Close() End Sub - Public WriteOnly Property XmlData() As String - Set(ByVal value As String) - userInfoXml = value + Public WriteOnly Property User() As TwitterDataModel.User + Set(ByVal value As TwitterDataModel.User) + Me.userInfo = value End Set End Property @@ -584,7 +566,7 @@ Private Sub UpdateProfileImage_RunWorkerCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs) Dim res As String = "" - Dim xdocbuf As String = "" + Dim user As TwitterDataModel.User = Nothing If e.Result Is Nothing Then Exit Sub @@ -594,21 +576,15 @@ ' アイコンを取得してみる ' が、古いアイコンのユーザーデータが返ってくるため反映/判断できない - res = MyOwner.TwitterInstance.GetUserInfo(_info.ScreenName, xdocbuf) - - Dim xdoc As New XmlDocument - Dim img As Image Try - xdoc.LoadXml(xdocbuf) - _info.ImageUrl = New Uri(xdoc.SelectSingleNode("/user/profile_image_url").InnerText) - img = (New HttpVarious).GetImage(_info.ImageUrl.ToString) + res = MyOwner.TwitterInstance.GetUserInfo(_info.ScreenName, user) + Dim img As Image = (New HttpVarious).GetImage(user.ProfileImageUrl) If img IsNot Nothing Then UserPicture.Image = img End If Catch ex As Exception End Try - End Sub Private Sub doChangeIcon(ByVal filename As String) Modified: trunk/Tween/Tween.vb =================================================================== --- trunk/Tween/Tween.vb 2010-12-09 14:22:14 UTC (rev 1191) +++ trunk/Tween/Tween.vb 2010-12-09 18:27:03 UTC (rev 1192) @@ -8792,12 +8792,13 @@ End Sub Private Sub OwnStatusMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OwnStatusMenuItem.Click - If Not String.IsNullOrEmpty(tw.UserInfoXml) Then - doShowUserStatus(tw.UserInfoXml) - Else - MessageBox.Show(My.Resources.ShowYourProfileText1, "Your status", MessageBoxButtons.OK, MessageBoxIcon.Information) - Exit Sub - End If + doShowUserStatus(tw.Username, False) + 'If Not String.IsNullOrEmpty(tw.UserInfoXml) Then + ' doShowUserStatus(tw.Username, False) + 'Else + ' MessageBox.Show(My.Resources.ShowYourProfileText1, "Your status", MessageBoxButtons.OK, MessageBoxIcon.Information) + ' Exit Sub + 'End If End Sub ' TwitterIDでない固定文字列を調べる(文字列検証のみ 実際に取得はしない) @@ -9308,17 +9309,17 @@ Private Class GetUserInfoArgs Public tw As Tween.Twitter Public id As String - Public xmlbuf As String + Public user As TwitterDataModel.User End Class Private Sub GetUserInfo_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs) Dim args As GetUserInfoArgs = DirectCast(e.Argument, GetUserInfoArgs) - e.Result = args.tw.GetUserInfo(args.id, args.xmlbuf) + e.Result = args.tw.GetUserInfo(args.id, args.user) End Sub Private Overloads Sub doShowUserStatus(ByVal id As String, ByVal ShowInputDialog As Boolean) Dim result As String = "" - Dim xmlbuf As String = "" + Dim user As TwitterDataModel.User = Nothing Dim args As New GetUserInfoArgs If ShowInputDialog Then Using inputName As New InputTabName() @@ -9330,7 +9331,7 @@ id = inputName.TabName.Trim args.tw = tw args.id = id - args.xmlbuf = xmlbuf + args.user = user Using _info As New FormInfo(Me, My.Resources.doShowUserStatusText1, _ AddressOf GetUserInfo_DoWork, _ Nothing, _ @@ -9338,7 +9339,7 @@ _info.ShowDialog() Dim ret As String = DirectCast(_info.Result, String) If String.IsNullOrEmpty(ret) Then - doShowUserStatus(args.xmlbuf) + doShowUserStatus(args.user) Else MessageBox.Show(ret) End If @@ -9348,7 +9349,7 @@ Else args.tw = tw args.id = id - args.xmlbuf = xmlbuf + args.user = user Using _info As New FormInfo(Me, My.Resources.doShowUserStatusText1, _ AddressOf GetUserInfo_DoWork, _ Nothing, _ @@ -9356,7 +9357,7 @@ _info.ShowDialog() Dim ret As String = DirectCast(_info.Result, String) If String.IsNullOrEmpty(ret) Then - doShowUserStatus(args.xmlbuf) + doShowUserStatus(args.user) Else MessageBox.Show(ret) End If @@ -9364,9 +9365,9 @@ End If End Sub - Private Overloads Sub doShowUserStatus(ByVal xmldata As String) + Private Overloads Sub doShowUserStatus(ByVal user As TwitterDataModel.User) Using userinfo As New ShowUserInfo() - userinfo.XmlData = xmldata + userinfo.User = user userinfo.ShowDialog(Me) End Using End Sub Modified: trunk/Tween/Twitter.vb =================================================================== --- trunk/Tween/Twitter.vb 2010-12-09 14:22:14 UTC (rev 1191) +++ trunk/Tween/Twitter.vb 2010-12-09 18:27:03 UTC (rev 1192) @@ -51,7 +51,6 @@ Private _statusesCount As Integer = 0 Private _location As String = "" Private _bio As String = "" - Private _userinfoxml As String = "" Private _protocol As String = "https://" 'プロパティからアクセスされる共通情報 @@ -101,17 +100,19 @@ Return "" Case HttpStatusCode.Unauthorized Twitter.AccountState = ACCOUNT_STATE.Invalid - Return "Check your Username/Password." + Dim errMsg As String = GetErrorMessageJson(content) + If String.IsNullOrEmpty(errMsg) Then + Return "Check your Username/Password." + Else + Return "Auth error:" + errMsg + End If Case HttpStatusCode.Forbidden - Dim xd As XmlDocument = New XmlDocument - Try - xd.LoadXml(content) - Dim xNode As XmlNode = Nothing - xNode = xd.SelectSingleNode("/hash/error") - Return "Err:" + xNode.InnerText - Catch ex As Exception + Dim errMsg As String = GetErrorMessageJson(content) + If String.IsNullOrEmpty(errMsg) Then Return "Err:Forbidden" - End Try + Else + Return "Err:" + errMsg + End If Case Else Return "Err:" + res.ToString + "(" + GetCurrentMethod.Name + ")" End Select @@ -125,6 +126,25 @@ _UserIdNo = "" End Sub + Private Function GetErrorMessageJson(ByVal content As String) As String + Try + If Not String.IsNullOrEmpty(content) Then + Using jsonReader As XmlDictionaryReader = JsonReaderWriterFactory.CreateJsonReader(Encoding.UTF8.GetBytes(content), XmlDictionaryReaderQuotas.Max) + Dim xElm As XElement = XElement.Load(jsonReader) + If xElm.Element("error") IsNot Nothing Then + Return xElm.Element("error").Value + Else + Return "" + End If + End Using + Else + Return "" + End If + Catch ex As Exception + Return "" + End Try + End Function + Public Sub Initialize(ByVal token As String, ByVal tokenSecret As String, ByVal username As String) 'xAuth認証 If String.IsNullOrEmpty(token) OrElse String.IsNullOrEmpty(tokenSecret) OrElse String.IsNullOrEmpty(username) Then @@ -308,35 +328,27 @@ End Function End Structure - Private Function IsPostRestricted(ByRef resMsg As String) As Boolean + Private Function IsPostRestricted(ByVal status As TwitterDataModel.Status) As Boolean Static _prev As New PostInfo("", "", "", "") Dim _current As New PostInfo("", "", "", "") + _current.CreatedAt = status.CreatedAt + _current.Id = status.IdStr + If status.Text Is Nothing Then + _current.Text = "" + Else + _current.Text = status.Text + End If + _current.UserId = status.User.IdStr - Dim xd As XmlDocument = New XmlDocument() - Try - xd.LoadXml(resMsg) - _current.CreatedAt = xd.SelectSingleNode("/status/created_at/text()").Value - _current.Id = xd.SelectSingleNode("/status/id/text()").Value - If xd.SelectSingleNode("/status/text/text()") Is Nothing Then - '制御文字のみ投稿した場合はNothing - _current.Text = "" - Else - _current.Text = xd.SelectSingleNode("/status/text/text()").Value - End If - _current.UserId = xd.SelectSingleNode("/status/user/id/text()").Value + If _current.Equals(_prev) Then + Return True + End If + _prev.CreatedAt = _current.CreatedAt + _prev.Id = _current.Id + _prev.Text = _current.Text + _prev.UserId = _current.UserId - If _current.Equals(_prev) Then - Return True - End If - _prev.CreatedAt = _current.CreatedAt - _prev.Id = _current.Id - _prev.Text = _current.Text - _prev.UserId = _current.UserId - Catch ex As XmlException - Return False - End Try - Return False End Function @@ -363,32 +375,24 @@ Select Case res Case HttpStatusCode.OK Twitter.AccountState = ACCOUNT_STATE.Valid - Dim xd As XmlDocument = New XmlDocument() + Dim status As TwitterDataModel.Status Try - xd.LoadXml(content) - Dim xNode As XmlNode = Nothing - xNode = xd.SelectSingleNode("/status/user/followers_count/text()") - If xNode IsNot Nothing Then _followersCount = Integer.Parse(xNode.Value) - xNode = xd.SelectSingleNode("/status/user/friends_count/text()") - If xNode IsNot Nothing Then _friendsCount = Integer.Parse(xNode.Value) - xNode = xd.SelectSingleNode("/status/user/statuses_count/text()") - If xNode IsNot Nothing Then _statusesCount = Integer.Parse(xNode.Value) - xNode = xd.SelectSingleNode("/status/user/location/text()") - If xNode IsNot Nothing Then _location = xNode.Value - xNode = xd.SelectSingleNode("/status/user/description/text()") - If xNode IsNot Nothing Then _bio = xNode.Value - xNode = xd.SelectSingleNode("/status/user/id/text()") - If xNode IsNot Nothing Then _UserIdNo = xNode.Value - - _userinfoxml = String.Copy(content) + status = CreateDataFromJson(Of TwitterDataModel.Status)(content) + Catch ex As SerializationException + TraceOut(ex.Message + Environment.NewLine + content) + Return "Err:Json Parse Error(DataContractJsonSerializer)" Catch ex As Exception - _userinfoxml = "" - Return "" + TraceOut(content) + Return "Err:Invalid Json!" End Try + _followersCount = status.User.FollowersCount + _friendsCount = status.User.FriendsCount + _statusesCount = status.User.StatusesCount + _location = status.User.Location + _bio = status.User.Description + _UserIdNo = status.User.IdStr - If Not postStr.StartsWith("D ", StringComparison.OrdinalIgnoreCase) AndAlso _ - Not postStr.StartsWith("DM ", StringComparison.OrdinalIgnoreCase) AndAlso _ - IsPostRestricted(content) Then + If IsPostRestricted(status) Then Return "OK:Delaying?" End If If op.Post(postStr.Length) Then @@ -397,15 +401,12 @@ Return "Outputz:Failed" End If Case HttpStatusCode.Forbidden, HttpStatusCode.BadRequest - Dim xd As XmlDocument = New XmlDocument - Try - xd.LoadXml(content) - Dim xNode As XmlNode = Nothing - xNode = xd.SelectSingleNode("/hash/error") - Return "Warn:" + xNode.InnerText - Catch ex As Exception - End Try - Return "Warn:" + res.ToString + Dim errMsg As String = GetErrorMessageJson(content) + If String.IsNullOrEmpty(errMsg) Then + Return "Warn:" + res.ToString + Else + Return "Warn:" + errMsg + End If Case HttpStatusCode.Conflict, _ HttpStatusCode.ExpectationFailed, _ HttpStatusCode.Gone, _ @@ -423,7 +424,12 @@ Return "Warn:" + res.ToString + "(" + GetCurrentMethod.Name + ")" Case HttpStatusCode.Unauthorized Twitter.AccountState = ACCOUNT_STATE.Invalid - Return "Check your Username/Password." + Dim errMsg As String = GetErrorMessageJson(content) + If String.IsNullOrEmpty(errMsg) Then + Return "Check your Username/Password." + Else + Return "Auth err:" + errMsg + End If Case Else Return "Err:" + res.ToString + "(" + GetCurrentMethod.Name + ")" End Select @@ -451,25 +457,22 @@ Select Case res Case HttpStatusCode.OK Twitter.AccountState = ACCOUNT_STATE.Valid - Dim xd As XmlDocument = New XmlDocument() + Dim status As TwitterDataModel.Status Try - xd.LoadXml(content) - Dim xNode As XmlNode = Nothing - xNode = xd.SelectSingleNode("/status/user/followers_count/text()") - If xNode IsNot Nothing Then _followersCount = Integer.Parse(xNode.Value) - xNode = xd.SelectSingleNode("/status/user/friends_count/text()") - If xNode IsNot Nothing Then _friendsCount = Integer.Parse(xNode.Value) - xNode = xd.SelectSingleNode("/status/user/statuses_count/text()") - If xNode IsNot Nothing Then _statusesCount = Integer.Parse(xNode.Value) - xNode = xd.SelectSingleNode("/status/user/location/text()") - If xNode IsNot Nothing Then _location = xNode.Value - xNode = xd.SelectSingleNode("/status/user/description/text()") - If xNode IsNot Nothing Then _bio = xNode.Value - xNode = xd.SelectSingleNode("/status/user/id/text()") - If xNode IsNot Nothing Then _UserIdNo = xNode.Value + status = CreateDataFromJson(Of TwitterDataModel.Status)(content) + Catch ex As SerializationException + TraceOut(ex.Message + Environment.NewLine + content) + Return "Err:Json Parse Error(DataContractJsonSerializer)" Catch ex As Exception - Return "" + TraceOut(content) + Return "Err:Invalid Json!" End Try + _followersCount = status.User.FollowersCount + _friendsCount = status.User.FriendsCount + _statusesCount = status.User.StatusesCount + _location = status.User.Location + _bio = status.User.Description + _UserIdNo = status.User.IdStr If op.Post(postStr.Length) Then Return "" @@ -477,15 +480,12 @@ Return "Outputz:Failed" End If Case HttpStatusCode.Forbidden, HttpStatusCode.BadRequest - Dim xd As XmlDocument = New XmlDocument - Try - xd.LoadXml(content) - Dim xNode As XmlNode = Nothing - xNode = xd.SelectSingleNode("/hash/error") - Return "Warn:" + xNode.InnerText - Catch ex As Exception - End Try - Return "Warn:" + res.ToString + Dim errMsg As String = GetErrorMessageJson(content) + If String.IsNullOrEmpty(errMsg) Then + Return "Warn:" + res.ToString + Else + Return "Warn:" + errMsg + End If Case HttpStatusCode.Conflict, _ HttpStatusCode.ExpectationFailed, _ HttpStatusCode.Gone, _ @@ -503,7 +503,12 @@ Return "Warn:" + res.ToString Case HttpStatusCode.Unauthorized Twitter.AccountState = ACCOUNT_STATE.Invalid - Return "Check your Username/Password." + Dim errMsg As String = GetErrorMessageJson(content) + If String.IsNullOrEmpty(errMsg) Then + Return "Check your Username/Password." + Else + Return "Auth err:" + errMsg + End If Case Else Return "Err:" + res.ToString + "(" + GetCurrentMethod.Name + ")" End Select @@ -910,7 +915,7 @@ End Select End Function - Public Function GetUserInfo(ByVal screenName As String, ByRef xmlBuf As String) As String + Public Function GetUserInfo(ByVal screenName As String, ByRef user As TwitterDataModel.User) As String If _endingFlag Then Return "" @@ -918,7 +923,7 @@ Dim res As HttpStatusCode Dim content As String = "" - xmlBuf = Nothing + user = Nothing Try res = twCon.ShowUserInfo(screenName, content) Catch ex As Exception @@ -927,22 +932,27 @@ Select Case res Case HttpStatusCode.OK - Dim xdoc As New XmlDocument - Dim result As String = "" Twitter.AccountState = ACCOUNT_STATE.Valid Try - xdoc.LoadXml(content) - xmlBuf = content + user = CreateDataFromJson(Of TwitterDataModel.User)(content) + Catch ex As SerializationException + TraceOut(ex.Message + Environment.NewLine + content) + Return "Err:Json Parse Error(DataContractJsonSerializer)" Catch ex As Exception - result = "Err:Invalid XML." - xmlBuf = Nothing + TraceOut(content) + Return "Err:Invalid Json!" End Try - Return result + Return "" Case HttpStatusCode.BadRequest Return "Err:API Limits?" Case HttpStatusCode.Unauthorized Twitter.AccountState = ACCOUNT_STATE.Invalid - Return "Check your Username/Password." + Dim errMsg As String = GetErrorMessageJson(content) + If String.IsNullOrEmpty(errMsg) Then + Return "Check your Username/Password." + Else + Return "Auth err:" + errMsg + End If Case Else Return "Err:" + res.ToString + "(" + GetCurrentMethod.Name + ")" End Select @@ -1328,12 +1338,6 @@ End Get End Property - Public ReadOnly Property UserInfoXml As String - Get - Return _userinfoxml - End Get - End Property - Public WriteOnly Property UseSsl() As Boolean Set(ByVal value As Boolean) HttpTwitter.UseSsl = value @@ -1461,26 +1465,6 @@ Return "" End Function - Private Function DateTimeParse(ByVal input As String) As Date - Dim rslt As Date - Dim format() As String = { - "ddd MMM dd HH:mm:ss zzzz yyyy" - } - For Each fmt As String In format - If DateTime.TryParseExact(input, _ - fmt, _ - System.Globalization.DateTimeFormatInfo.InvariantInfo, _ - System.Globalization.DateTimeStyles.None, _ - rslt) Then - Return rslt - Else - Continue For - End If - Next - TraceOut("Parse Error(DateTimeFormat) : " + input) - Return New Date - End Function - Private Function CreatePostsFromStatusData(ByVal status As TwitterDataModel.Status) As PostClass Dim post As New PostClass @@ -2894,7 +2878,7 @@ End Try Dim evt As New FormattedEvent - evt.CreatedAt = Me.DateTimeParse(eventData.CreatedAt) + evt.CreatedAt = DateTimeParse(eventData.CreatedAt) evt.Event = eventData.Event evt.Username = eventData.Source.ScreenName Select Case eventData.Event