1 ' Tween - Client of Twitter
2 ' Copyright (c) 2007-2011 kiri_feather (@kiri_feather) <kiri.feather@gmail.com>
3 ' (c) 2008-2011 Moz (@syo68k)
4 ' (c) 2008-2011 takeshik (@takeshik) <http://www.takeshik.org/>
5 ' (c) 2010-2011 anis774 (@anis774) <http://d.hatena.ne.jp/anis774/>
6 ' (c) 2010-2011 fantasticswallow (@f_swallow) <http://twitter.com/f_swallow>
9 ' This file is part of Tween.
11 ' This program is free software; you can redistribute it and/or modify it
12 ' under the terms of the GNU General Public License as published by the Free
13 ' Software Foundation; either version 3 of the License, or (at your option)
16 ' This program is distributed in the hope that it will be useful, but
17 ' WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 ' or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 ' You should have received a copy of the GNU General Public License along
22 ' with this program. If not, see <http://www.gnu.org/licenses/>, or write to
23 ' the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
24 ' Boston, MA 02110-1301, USA.
31 Inherits HttpConnectionOAuthEcho
37 Private Const ConsumerKey As String = "tLbG3uS0BIIE8jm1mKzKOfZ6EgUOmWVM"
40 '''OAuthの署名作成用秘密コンシューマーデータ
42 Private Const ConsumerSecretKey As String = "M0IMsbl2722iWa+CGPVcNeQmE+TFpJk8B/KW9UUTk3eLOl9Ij005r52JNxVukTzM"
44 Private Const PostMethod As String = "POST"
45 Private Const GetMethod As String = "GET"
46 Private Const ApiKey As String = "287b60562aea3cab9f58fa54015848e8"
47 Private pictureExt() As String = {".jpg", _
52 Private Const MaxFileSize As Long = 5 * 1024 * 1024
54 Public Function Upload(ByVal mediaFile As FileInfo, _
55 ByVal message As String, _
56 ByRef content As String) As HttpStatusCode
58 If String.IsNullOrEmpty(message) Then message = ""
59 'Check filetype and size(Max 5MB)
60 If Array.IndexOf(pictureExt, mediaFile.Extension.ToLower) > -1 Then
61 If mediaFile.Length > MaxFileSize Then Throw New ArgumentException("File is too large.")
63 Throw New ArgumentException("Service don't support this filetype.")
66 Dim param As New Dictionary(Of String, String)
67 param.Add("key", ApiKey)
68 param.Add("message", message)
69 Dim binary As New List(Of KeyValuePair(Of String, FileInfo))
70 binary.Add(New KeyValuePair(Of String, FileInfo)("media", mediaFile))
71 Me.InstanceTimeout = 60000 'タイムアウト60秒
73 Return GetContent(PostMethod, _
74 New Uri("http://api.twitpic.com/2/upload.xml"), _
82 Public Function CheckValidExtension(ByVal ext As String) As Boolean
83 If Array.IndexOf(pictureExt, ext.ToLower) > -1 Then
89 Public Function GetFileOpenDialogFilter() As String
90 Return "Image Files(*.gif;*.jpg;*.jpeg;*.png)|*.gif;*.jpg;*.jpeg;*.png"
93 Public Function GetFileType(ByVal ext As String) As UploadFileType
94 If Array.IndexOf(pictureExt, ext.ToLower) > -1 Then
95 Return UploadFileType.Picture
97 Return UploadFileType.Invalid
100 Public Function IsSupportedFileType(ByVal type As UploadFileType) As Boolean
101 Return type.Equals(UploadFileType.Picture)
104 Public Function GetMaxFileSize(ByVal ext As String) As Long
105 If Array.IndexOf(pictureExt, ext.ToLower) > -1 Then
111 Public Sub New(ByVal accessToken As String, ByVal accessTokenSecret As String)
112 MyBase.New(New Uri("http://api.twitter.com/"), _
113 New Uri("https://api.twitter.com/1/account/verify_credentials.json"))
114 Initialize(DecryptString(ConsumerKey), DecryptString(ConsumerSecretKey), accessToken, accessTokenSecret, "")