Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

LuisHD

Ferramenta pra Twitter

Recommended Posts

Boa Tarde.

 

preciso de uma ferramenta que é o seguinte, sempre que o assunto humor for citado por qualqer pessoa do twitter, dispara um twet meu para essa pessoa entende?

 

Alguem sabe como fazer? pra pode me ajudar?

Compartilhar este post


Link para o post
Compartilhar em outros sites

olha esta classe, Library Twitter é um pequeno script escrito em ASP (VBScript) que permite que você atualizar, recuperar, formatar e apresentar o seu tweets e perfil clássico dentro do seu aplicativo ASP. A ideia subjacente a este script ASP Classic é ajudar desenvolvedores a integrar a sua aplicação com twister, como ferramentas para desenvolvedores WordPress.

 

Alguns métodos:

1.Twitter REST API usuário show (ref função: aspTwitterUserDetail), permitem-lhe obter detalhe do seu perfil

2.Twitter REST API usuário timeline (ref função: aspTwitterGetUserTimeline) permitem-lhe obter o seu mais recente twitter status

3.Twitter REST API status update (ref função: aspTwitterUpdateStatus) permitem que você atualize twitter status dentro de sua página ASP

 

Algumas funções comuns utilizados na twister:

 

1.Autolink, vire formato válido de URL no seu twitter status clickable link em texto

2.Short URL (redirecionamento URL) classe, permite que você crie short url dentro da sua página ASP. suporta: tinyurl, is.gd, bit.ly, hex.io (padrão: tinyurl)

 

asp_twitter_lib.asp

<!--#include file="atl_short_url.asp" -->
<%
'************************************************************************
'* @TITLE:			AspTwitterLib (VBScript Twitter API Class)
'* @PACKAGE:		AspTwitterLib
'* @DESCRIPTION:	Classe de update, get,formatar e apresentar dados twister com VBScript e Twitter API
'* @VERSION			0.1		
'* @DATE:			May 15 2009
'* @TODO:			Implement more twitter API
'************************************************************************
class AspTwitterLib
'********************************
'* Classe Declaração
'********************************
private m_ObjXmlHttp			'[object] Microsoft.XMLHTTP Object
private m_ObjParams				'[object] COM Object Scripting Dictionary
private m_StrFormat				'[string] Retornar Format (actualmente apenas suportam XML)
private m_StrUser				'[string] Login Name
private m_StrPassword			'[string] password
private m_ObjUrl				'[object] url objeto << twitter_short_url.asp
private m_StrErrorMessage		'[string] atual mensagem de erro
private m_StrLastErrorMessage	'[string] última mensagem de erro
private m_IntHttpStatus			'[integer] HTTP Response Status
private m_StrLastHttpStatus		'[integer] Última resposta HTTP Status

'********************************
'* Formato dos dados propriedade assignment
'* [Actual execução] só permite XML 
'********************************
Public Property Let aspTwitterDataFormat(strFormat)
	'if not (strFormat="xml" or strFormat="json" or strFormat="rss" or strFormat="atom") then
		m_StrFormat = "xml"
	'else
	'	m_StrFormat = strFormat
	'end if
End Property

'********************************
'* Usuário propriedade assignment
'********************************
Public Property Let aspTwitterLoginUser(strUser)
	m_StrUser = strUser
End Property

'********************************
'* Password propriedade assignment
'********************************
Public Property Let aspTwitterLoginPass(strPass)
	m_StrPassword = strPass
End Property

'********************************
'* get Error Status
'********************************
public property get aspTwitterError()
	aspTwitterError=m_StrErrorMessage
end property

'********************************
'* get HTTP Status
'********************************
public property get aspTwitterHttp()
	aspTwitterHttp=m_IntHttpStatus
end property

'********************************
'* Objeto Server 
'* 1. m_ObjXmlHttp : Msxml2.ServerXMLHTTP.3.0
'* 2. m_ObjParams : Scripting.Dictionary
'********************************
private sub createServerObject()
	if not isObject(m_ObjXmlHttp) then set m_ObjXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP.3.0")
	if not isObject(m_ObjParams) then Set m_ObjParams=Server.CreateObject("Scripting.Dictionary")		
end sub

'********************************
'* Destroi Objeto server
'********************************
private sub destroyServerObject()
	if isObject(m_ObjXmlHttp) then set m_ObjXmlHttp = nothing
	if isObject(m_ObjParams) then Set m_ObjParams = nothing
	if isObject(m_ObjUrl) then Set m_ObjUrl = nothing
end sub

'********************************
'* Autolink HTML text
'* params: [string:html]
'********************************
private function aspTwitterAutolink(strHtml)
	Dim objRegex,strReturn
	set objRegex = new regexp
	objRegex.Pattern = "(\b(?:(?:https?|ftp|file)://|www\.|ftp\.)(?:\([-A-Z0-9+&@#/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#/%=~_|$?!:,.]*\)|[A-Z0-9+&@#/%=~_|$]))"
	objRegex.IgnoreCase = true
	objRegex.Global = true
	strReturn = objRegex.Replace(strHtml, "<a href=""$1"" rel = ""nofollow"" target = ""_blank"">$1</a>")
	set objRegex = nothing
	aspTwitterAutolink = strReturn
end function

'********************************
'* Params assignment
'* arrParams : array -> key_1=val_1, key_2=val_2 
'********************************
private sub aspTwitterSetParams(arrParams)
	m_ObjParams.removeAll
	if isArray(arrParams) then
		Dim tmpParam
		for each i in arrParams
			tmpParam = split(i,"=")
			if Ubound(tmpParam) = 1 then
				m_ObjParams.Add tmpParam(0),tmpParam(1)
			end if
		next
	end if
end sub	

'********************************
'* Mensagem de erro Check Status
'* param: [xml: twitter response]
'********************************
private function aspTwitterCheckError(strXmlResponse)
	Dim strErrorMsg:strErrorMsg  = ""
	' personalize error message
	select case m_IntHttpStatus
		case 400
			strErrorMsg = "Bad Request: O pedido foi inválido. " & _ 
						  "É causada por uma baixa conexão à Internet ou " & _ 
						  "<a href=""http://apiwiki.twitter.com/Rate-limiting"" target=""_blank"">Twitter's limitação da taxa</a>"
		case 401 
			strErrorMsg = "Não Autorizado: autenticação de credenciais estavam em falta ou incorrectas. Verifique o seu nome de usuário & password"
		case 403 
			strErrorMsg = "Proibido: O pedido foi recusado pelo servidor de twister"
		case 404 
			strErrorMsg = "A URL solicitada é inválida ou o recurso solicitado, tais como usuário, não existe."	
		case 406 
			strErrorMsg = "Não Aceitável: formato invalido dos dados solicitados, verificar a sua opção de formatação dos dados."
		case 500 
			strErrorMsg = "Internal Server Error: Algo está quebrado. Por favor <a href=""http://apiwiki.twitter.com/Support"">post para o grupo </ a> para que possamos investigar."
		case 502
			strErrorMsg = "Bad Gateway: Twitter esta baixo ou esta sendo atualizado."
		case 503
			strErrorMsg = "Service Unavailable: Os servidores Twitter  estão sobrecarregados com os pedidos. Tente novamente mais tarde."
		case else
			if Len(strXmlResponse) > 0 then
				Dim objXmlDom:set objXmlDom = Server.CreateObject("Microsoft.XMLDOM")
				objXmlDom.async = false
				objXmlDom.loadxml(strXmlResponse)
				objXmlDom.setProperty "SelectionLanguage", "XPath"

				Dim objSingleNode
				Set objSingleNode = objXmlDom.selectSingleNode("//hash/error")
				if not objSingleNode is nothing then
					strErrorMsg= objSingleNode.Text
				end if
				Set objXmlDom = Nothing
			else	
				strErrorMsg  = "Não houve dados para retornar."
			end if
	end select
	aspTwitterCheckError = strErrorMsg
end function

'********************************
'* exemplo inicialização
'********************************
sub class_initialize()
	call createServerObject
	call aspTwitterShortUrlInit(false,false,false)
end sub

'********************************
'* exemplo rescisão
'********************************
sub class_terminate()
	call destroyServerObject
end sub

'********************************
'* Error Status
'********************************
public sub aspTwitterWriteError(strBefore,strAfter)
	if len(strBefore) = 0 then strBefore = "<p class=""error"">"
	if len(strAfter) = 0 then strAfter = "</p>"
	Response.Write strBefore&m_StrErrorMessage&strAfter
end sub

'********************************
'* encurtar Url
'* params: [string:provider], [string:user login], [string:api key]
'********************************
public sub aspTwitterShortUrlInit(strProvider,strUser,strApi)
	if not isObject(m_ObjUrl) then Set m_ObjUrl= new ATLShortUrl
	if strProvider then m_ObjUrl.aspSetProvider = strProvider
	if strUser then m_ObjUrl.aspSetUser = strUser
	if strApi then m_ObjUrl.aspSetApi = strApi
end sub

'********************************
'* Url encurtar execução
'* params: [string:long url]
'********************************
public function aspTwitterShortUrlGet(strUrl)
	if Len(strUrl) > 0 then 
		aspTwitterShortUrlGet = m_ObjUrl.aspShortUrlExec(strUrl)
	end if
end function

'********************************
'* Obter Detalhes do usuário 
'* Retorno : Dictionary Object
'* Ref : http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-users show
'********************************
public function aspTwitterUserDetail()
	Dim strApiUrl:strApiUrl = "http://twitter.com/users/show."&m_StrFormat
	call aspTwitterSetParams(array("id="&m_StrUser))
	Dim xmlResult:xmlResult = aspTwitterCall(strApiUrl,false,false)
	Dim objDictionary:Set objDictionary = Server.CreateObject("Scripting.Dictionary")
	if Len(xmlResult)>0 then
		Dim objXmlDom
		set objXmlDom = Server.CreateObject("Microsoft.XMLDOM")
		objXmlDom.async = false
		objXmlDom.loadxml(xmlResult)
		objXmlDom.setProperty "SelectionLanguage", "XPath"

		Dim objRootNode,strNode
		Set objRootNode = objXmlDom.documentElement
		For Each strNode In objRootNode.childNodes 
			if not strNode.nodeName = "status" then
				objDictionary.Add strNode.nodeName,strNode.text
			end if
		Next
		Set objRootNode = nothing
		Set objXmlDom = nothing
	End if
	Set aspTwitterUserDetail = objDictionary
	Set objDictionary = Nothing
end function


'********************************
'* User Timeline
'* Retorno : Array(array(date_1,text_1,source_1,reply_screen_name_1),array(date_2,text_2,source_2,reply_screen_name_2))
'* ref : http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses-user_timeline
'********************************
public function aspTwitterGetUserTimeline()
	Dim strApiUrl:strApiUrl = "http://twitter.com/statuses/user_timeline."&m_StrFormat
	call aspTwitterSetParams(array("id="&m_StrUser))
	Dim strXmlReturn:strXmlReturn = aspTwitterCall(strApiUrl,false,false)
	if Len(strXmlReturn) > 0 then strXmlReturn=aspTwitterFormatXml(strXmlReturn)
	aspTwitterGetUserTimeline = strXmlReturn
end function

'********************************
'* Formato timeline
'* param : XML
'* Retorno : Array(array(date_1,text_1,source_1,reply_screen_name_1),array(date_2,text_2,source_2,reply_screen_name_2))
'* ref : http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses-user_timeline
'********************************
private function aspTwitterFormatXml(strXml)
	Dim objXmlDom:set objXmlDom = Server.CreateObject("Microsoft.XMLDOM")
	With objXmlDom
		.async = false
		.setProperty "SelectionLanguage", "XPath"
		.loadxml(strXml)
	End With

	Dim objRootNode:Set objRootNode = objXmlDom.selectNodes("/statuses/status")

	Dim intCounter:intCounter = 0

	' date,text,source,reply_screen_name
	Dim arrUserStatus()

	Dim oUserNodes
	Dim iDate,iText,iSource,iReply,iHolders(4)
	For Each oUserNodes in objRootNode
		redim preserve arrUserStatus(intCounter+1)
		iHolders(0) = oUserNodes.selectSingleNode("created_at").Text
		iHolders(1) = aspTwitterAutolink(oUserNodes.selectSingleNode("text").Text)
		iHolders(2) = oUserNodes.selectSingleNode("source").Text
		iHolders(3) = oUserNodes.selectSingleNode("in_reply_to_screen_name").Text
		arrUserStatus(intCounter) = iHolders
		intCounter = intCounter + 1
	Next

	Set oUserNodes = Nothing
	Set objRootNode = Nothing
	Set objXmlDom = Nothing

	aspTwitterFormatXml=arrUserStatus 
end function

'********************************
'* Update User Status
'* strStatus : (string) status
'* Retorno : XML
'* Ref : http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses%C2%A0update
'********************************
public sub aspTwitterUpdateStatus(strStatus)
	Dim strApiUrl:strApiUrl = "http://twitter.com/statuses/update."&m_StrFormat
	Dim arrTmpParams: arrTmpParams = array("status="&strStatus,"source=VBScriptTwitter")
	call aspTwitterSetParams(arrTmpParams)
	call aspTwitterCall(strApiUrl,true,true)
end sub

'********************************
'*Abrir página remota 
'* Retorno: Conteúdo da página Remoto (XML?)
'********************************
public function aspTwitterCall(strUrl,bolPost,bolLogin)

	Dim strParameters,intTimeout
	intTimeout = 5000
	if isObject(m_ObjParams) then
		for each i in m_ObjParams
			if len(i) > 0 and len(m_ObjParams.Item(i)) > 0 then 
				strParameters = strParameters & "&"&i&"="&server.URLencode(m_ObjParams.Item(i))
			end if
		next
	end if

	m_StrErrorMessage = ""
	m_IntHttpStatus = 200

	if bolPost then
		if bolLogin then
			m_ObjXmlHttp.Open "POST", strUrl, false, m_StrUser, m_StrPassword
		else
			m_ObjXmlHttp.Open "POST", strUrl, false
		end if
		m_ObjXmlHttp.setTimeouts intTimeout, intTimeout, intTimeout, intTimeout
		m_ObjXmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
		if len(strParameters) > 0 then 
			strParameters = Mid(strParameters,2)
			m_ObjXmlHttp.Send strParameters
		else
			m_ObjXmlHttp.Send null
		end if
	else
		if len(strParameters) > 0 then 
			strParameters = Mid(strParameters,2)
			Dim intStrPos
			intStrPos = Instr(strUrl, "?")
			if not IsNull(intStrPos) and intStrPos > 0 then 
				strUrl = strUrl & "&"
			else
				strUrl = strUrl & "?"
			end if
			strUrl = strUrl & strParameters
		end if
		m_ObjXmlHttp.Open "GET", strUrl, false
		m_ObjXmlHttp.setTimeouts intTimeout, intTimeout, intTimeout, intTimeout
		m_ObjXmlHttp.Send null
	end if

	m_IntHttpStatus = m_ObjXmlHttp.status

	Dim strXmlResponse:strXmlResponse = m_ObjXmlHttp.responseText

	Dim strRequestStatus:strRequestStatus = aspTwitterCheckError(strXmlResponse)
	if Len(strRequestStatus) > 0 then
		m_StrErrorMessage = strRequestStatus
		strXmlResponse = ""
	end if
	aspTwitterCall = strXmlResponse
end function
end class
%>

 

atl_short_url.asp

<%
class ATLShortUrl

private m_StrProvider,m_StrApiUrl,m_StrUserName,m_StrApiKey

public property let aspSetProvider(strProvider)
	m_StrProvider = Lcase(strProvider)
	select case m_StrProvider
		case "bitly"
			m_StrApiUrl = "http://api.bit.ly/shorten?version=2.0.1&format=xml&longUrl=[:URL:]&login=[:LOGIN:]&apiKey=[:API:]"
		case "isgd"
			m_StrApiUrl = "http://is.gd/api.php?longurl=[:URL:]"
		case "hexio"
			m_StrApiUrl = "http://hex.io/api-create.php?url=[:URL:]"
		case else
			m_StrApiUrl = "http://tinyurl.com/api-create.php?url=[:URL:]"
	end select
end property

public property let aspSetUser(strUser)
	m_StrUserName = strUser
end property

public property let aspSetApi(strApi)
	m_StrApiKey = strApi
end property

sub class_initialize()
	me.aspSetProvider = "tinyurl"
	m_StrUserName = m_StrApiKey = ""
end sub

sub class_terminate()
end sub

private function aspGrabUrl(strUrl)
	select case m_StrProvider
		case "bitly"
			Dim oXmlDom,strGrabUrl
			set oXmlDom = Server.CreateObject("Microsoft.XMLDOM")
			oXmlDom.async = false
			oXmlDom.setProperty "SelectionLanguage", "XPath"
			oXmlDom.loadxml(strUrl)
			strGrabUrl = oXmlDom.selectSingleNode("/bitly/results/nodeKeyVal/shortUrl").Text
			Set oXmlDom = Nothing
			aspGrabUrl = strGrabUrl
		case else
			aspGrabUrl = strUrl
	end select
end function

public function aspShortUrlExec(strUrl)
	if Len(m_StrApiUrl) > 0 then
		Dim oXml,strRealUrl,strShortUrl
		strRealUrl = Replace(m_StrApiUrl, "[:URL:]", strUrl, 1, -1, 1)
		strRealUrl = Replace(strRealUrl, "[:LOGIN:]", m_StrUserName, 1, -1, 1)
		strRealUrl = Replace(strRealUrl, "[:API:]", m_StrApiKey, 1, -1, 1)
		set oXml = Server.CreateObject("Msxml2.ServerXMLHTTP.3.0")
		oXml.Open "GET", strRealUrl, false
		oXml.Send null
		strShortUrl = oXml.responseText
		Set oXml = nothing
		aspShortUrlExec = aspGrabUrl(strShortUrl)
	else
		aspShortUrlExec = false
	end if
end function

end class
%>

 

index.asp

<!--#include file="asp_twitter_lib.asp" -->
<%
Dim oTwitterAPI
set oTwitterAPI = new AspTwitterLib
oTwitterAPI.aspTwitterDataFormat = "xml" ' atualmente somente suporte XML
oTwitterAPI.aspTwitterLoginUser = "seu_twitter_login"
oTwitterAPI.aspTwitterLoginPass = "seu_twitter_password"

Dim objUserDetail,strUserDetailError
Set objUserDetail = oTwitterAPI.aspTwitterUserDetail()
if Len(oTwitterAPI.aspTwitterError) > 0 then
	strUserDetailError =  "<p class=""error"">" & _ 
						  "Oops error detalhe do user: " & _
						  "<cite><small>" & oTwitterAPI.aspTwitterError & "<small></cite></p>"
else
	Dim arrTimeline,strTimelineError
	arrTimeline = oTwitterAPI.aspTwitterGetUserTimeline()
	if Len(oTwitterAPI.aspTwitterError) > 0 then
	strTimelineError =  "<p class=""error"">" & _ 
						  "Oops unabled fetching usuário : " & _
						  "<cite><small>" & oTwitterAPI.aspTwitterError & "<small></cite></p>"
	end if
end if
%>
<html>
<head>
	<title>Classic ASP Twitter API</title>
	<style type="text/css">
		* { padding:0; margin:0; }
		body { padding:25px; margin:0; background:#f5f5f5; color:#666; font-family:arial; font-size:20px; text-align:center; }
		#wrap { text-align:left; background:#fff; width:600px; margin:0px auto; }
		#twitter { padding-bottom:20px; }
		h1 { font-size:30px; letter-spacing:-2px; padding:20px; }
		ul {}
		ul li { border-top:solid 1px #f5f5f5; padding:10px 30px; list-style:none; display:block; }
		ul li.alt { background:#f6f9d0; }
		small { color:#999; font-size:14px; }
		a { color:#999; }
		#user { margin:20px 30px; width:100%; overflow:hidden; }
		#user img { border:solid 5px #ccc; float:left; margin:0px 10px 10px 0px; }
		#user ul li { border:none; }
		p.error { padding:0px 25px; }
		#twitter p.error cite { color:red!important; }
	</style>
</head>
<body>
	<div id="wrap">
	<div id="twitter">
	<h1>Classic ASP Twitter API</h1>
	<%
	if Len(strUserDetailError) > 0 then
		response.write strUserDetailError
	else
		%>
		<div id="user">
			<img src="<%= objUserDetail.Item("profile_image_url") %>" alt="" />
			<strong><%=objUserDetail.Item("name")%> (<%=objUserDetail.Item("screen_name")%>)</strong> in 
			<%=objUserDetail.Item("location")%><br />
			<small><a href="<%=objUserDetail.Item("url")%>" rel="nofollow" target="_blank"><%=objUserDetail.Item("url")%></a>
			<br /><%=objUserDetail.Item("description")%><br />
			No momento <%=objUserDetail.Item("friends_count")%> pessoas, 
			seguido por <%=objUserDetail.Item("followers_count")%> pessoas e tem <%=objUserDetail.Item("statuses_count")%> Status update</small>
			<br clear="both" />
		</div>
		<%
		if Len(strTimelineError) > 0 then
			response.write	strTimelineError
		else
			if IsArray(arrTimeline) then
				%><ul><%
				Dim intCounter,strStyle
				intCounter = 0
				for each i in arrTimeline
					if isArray(i) then
						strStyle = ""
						if intCounter MOD 2 = 0 then strStyle = "alt"
						%><li class="<%=strStyle%>"><%=i(1)%><br /><small>postado às <%=i(0)%> de <%=i(2)%></small></li><%
						intCounter = intCounter + 1
					end if
				next
				%></ul><%
			Else
				response.Write "<p>Atualmente "&objUserDetail.Item("name")&" não tem estado atualização</p>"
			End if
		end if
	end if
	%>
	</div>
	</div>
</body>
</html>
<% Set objUserDetail = Nothing:Set oTwitterAPI = Nothing %>

 

update_status.asp

<!--#include file="asp_twitter_lib.asp" -->
<%
'*************************************************
'* @ amostra de atualização twister com status AspTwitterLib
'*************************************************
Dim oTwitterAPI:set oTwitterAPI = new AspTwitterLib
oTwitterAPI.aspTwitterLoginUser = "seu_twitter_login"
oTwitterAPI.aspTwitterLoginPass = "seu_twitter_password"

oTwitterAPI.aspTwitterUpdateStatus("Testando atualização de status AspTwitterLib, ASP (VBScript) Biblioteca de Twitter API")

if Len(oTwitterAPI.aspTwitterError) > 0 then
response.write "Opa ocorreu erro : "&oTwitterAPI.aspTwitterError
else
Response.Write "Status Updated"
end if

Set oTwitterAPI = nothing
%>

 

========================

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

twitter 2

 

index.asp

 

<!--#include file="asp_twitter_lib.asp" -->
<%
Dim oTwitterAPI
set oTwitterAPI = new AspTwitterLib
oTwitterAPI.aspTwitterLoginUser = "usuario"
oTwitterAPI.aspTwitterLoginPass = "senha"

Dim objUserDetail,strUserDetailError
Set objUserDetail = oTwitterAPI.aspTwitterUserDetail()
if Len(oTwitterAPI.aspTwitterError) > 0 then
	strUserDetailError =  "<p class=""error"">" & _ 
						  "Oops error fetching user detail : " & _
					      "<cite><small>" & oTwitterAPI.aspTwitterError & "<small></cite></p>"
else
	Dim arrTimeline,strTimelineError
	arrTimeline = oTwitterAPI.aspTwitterGetUserTimeline()
	if Len(oTwitterAPI.aspTwitterError) > 0 then
	strTimelineError =  "<p class=""error"">" & _ 
						  "Oops unabled fetching user statuses : " & _
					      "<cite><small>" & oTwitterAPI.aspTwitterError & "<small></cite></p>"
	end if
end if
%>
<html>
<head>
	<title>Classic ASP Twitter API</title>
	<style type="text/css">
		* { padding:0; margin:0; }
		body { padding:25px; margin:0; background:#f5f5f5; color:#666; font-family:arial; font-size:20px; text-align:center; }
		#wrap { text-align:left; background:#fff; width:600px; margin:0px auto; }
		#twitter { padding-bottom:20px; }
		h1 { font-size:30px; letter-spacing:-2px; padding:20px; }
		ul {}
		ul li { border-top:solid 1px #f5f5f5; padding:10px 30px; list-style:none; display:block; }
		ul li.alt { background:#f6f9d0; }
		small { color:#999; font-size:14px; }
		a { color:#999; }
		#user { margin:20px 30px; width:100%; overflow:hidden; }
		#user img { border:solid 5px #ccc; float:left; margin:0px 10px 10px 0px; }
		#user ul li { border:none; }
		p.error { padding:0px 25px; }
		#twitter p.error cite { color:red!important; }
	</style>
</head>
<body>
	<div id="wrap">
	<div id="twitter">
	<h1>Classic ASP Twitter API</h1>
	<%
	if Len(strUserDetailError) > 0 then
		response.write strUserDetailError
	else
		%>
		<div id="user">
			<img src="<%= objUserDetail.Item("profile_image_url") %>" alt="" />
			<strong><%=objUserDetail.Item("name")%> (<%=objUserDetail.Item("screen_name")%>)</strong> in 
			<%=objUserDetail.Item("location")%><br />
			<small><a href="<%=objUserDetail.Item("url")%>" rel="nofollow" target="_blank"><%=objUserDetail.Item("url")%></a>
			<br /><%=objUserDetail.Item("description")%><br />
			Currently following <%=objUserDetail.Item("friends_count")%> peoples, 
			followed by <%=objUserDetail.Item("followers_count")%> peoples and 
			has <%=objUserDetail.Item("statuses_count")%> Statuses update</small>
			<br clear="all" />
		</div>
		<%
		if Len(strTimelineError) > 0 then
			response.write	strTimelineError
		else
			if IsArray(arrTimeline) then
				%><ul><%
				Dim intCounter,strStyle
				intCounter = 0
				for each i in arrTimeline
					if isArray(i) then
						strStyle = ""
						if intCounter MOD 2 = 0 then strStyle = "alt"
						%><li class="<%=strStyle%>"><%=i(1)%><br /><small>posted at <%=i(0)%> from <%=i(2)%></small></li><%
						intCounter = intCounter + 1
					end if
				next
				%></ul><%
			Else
				response.Write "<p>Currently "&objUserDetail.Item("name")&" has no status update</p>"
			End if
		end if
	end if
	%>
	</div>
	</div>
</body>
</html>
<% Set objUserDetail = Nothing:Set oTwitterAPI = Nothing %>

 

asp_twitter_lib.asp

 

<!--#include file="atl_short_url.asp" -->
<%
'************************************************************************
'* Copyright (c) <2009> Ariel G. Saputra <webmaster@asp.web.id>
'*
'*	This program is free software: you can redistribute it and/or modify
'*  it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by
'*  the Free Software Foundation, either version 3 of the License, or
'*  any later version.

'*  This program is distributed in the hope that it will be useful,
'*  but WITHOUT ANY WARRANTY; without even the implied warranty of
'*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'*  GNU General Public License for more details.

'*  You should have received a copy of the GNU General Public License
'*  along with this program.  If not, see <http://www.gnu.org/licenses/>.
'************************************************************************

'************************************************************************
'* @TITLE:			AspTwitterLib (VBScript Twitter API Class)
'* @PACKAGE:		AspTwitterLib
'* @AUTHOR: 		Ariel G. Saputra <webmaster@asp.web.id>
'* @DESCRIPTION:	Class to update, get, format and display twitter data with VBScript and Twitter API
'* @VERSION			0.1		
'* @DATE:			May 15 2009
'* @TODO:			Implement more twitter API
'************************************************************************
class AspTwitterLib
'********************************
'* Class Member Declaration
'********************************
private m_ObjXmlHttp			'[object] Microsoft.XMLHTTP Object
private m_ObjParams				'[object] COM Object Scripting Dictionary (* hold params for each XMLHTTP Request)
private m_ObjAccount			'[object] COM Object Scripting Dictionary (* hold detail account after cridential verifications)
private m_StrFormat				'[string] Return Format (currently only support XML)
private m_StrUser				'[string] Login Name
private m_StrPassword			'[string] password
private m_ObjUrl				'[object] Shortenize url object << twitter_short_url.asp
private m_StrErrorMessage		'[string] current error message
private m_StrLastErrorMessage	'[string] last error message
private m_IntHttpStatus			'[integer] HTTP Response Status
private m_StrLastHttpStatus		'[integer] Last HTTP Response Status

'********************************
'* Data format property assignment
'* [current implementation] only XML allowed
'********************************
Public Property Let aspTwitterDataFormat(strFormat)
	'if not (strFormat="xml" or strFormat="json" or strFormat="rss" or strFormat="atom") then
		m_StrFormat = "xml"
	'else
	'	m_StrFormat = strFormat
	'end if
End Property

'********************************
'* User property assignment
'********************************
Public Property Let aspTwitterLoginUser(strUser)
	m_StrUser = strUser
End Property

'********************************
'* Password Property assignment
'********************************
Public Property Let aspTwitterLoginPass(strPass)
	m_StrPassword = strPass
End Property

'********************************
'* get Error Status
'********************************
public property get aspTwitterError()
	aspTwitterError=m_StrErrorMessage
end property

'********************************
'* get HTTP Status
'********************************
public property get aspTwitterHttp()
	aspTwitterHttp=m_IntHttpStatus
end property

'********************************
'* Server Object Creations
'* 1. m_ObjXmlHttp : Msxml2.ServerXMLHTTP.3.0
'* 2. m_ObjParams : Scripting.Dictionary
'********************************
private sub createServerObject()
	if not isObject(m_ObjXmlHttp) then set m_ObjXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP.3.0")
	if not isObject(m_ObjParams) then Set m_ObjParams=Server.CreateObject("Scripting.Dictionary")
	if not isObject(m_ObjAccount) then Set m_ObjAccount=Server.CreateObject("Scripting.Dictionary")
end sub

'********************************
'* Destroy server objects
'********************************
private sub destroyServerObject()
	if isObject(m_ObjXmlHttp) then set m_ObjXmlHttp = nothing
	if isObject(m_ObjParams) then Set m_ObjParams = nothing
	if isObject(m_ObjAccount) then Set m_ObjAccount = nothing
	if isObject(m_ObjUrl) then Set m_ObjUrl = nothing
end sub

'********************************
'* Autolink HTML text
'* params: [string:html]
'********************************
private function aspTwitterAutolink(strHtml)
	Dim objRegex,strReturn
	set objRegex = new regexp
	objRegex.Pattern = "(\b(?:(?:https?|ftp|file)://|www\.|ftp\.)(?:\([-A-Z0-9+&@#/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#/%=~_|$?!:,.]*\)|[A-Z0-9+&@#/%=~_|$]))"
	objRegex.IgnoreCase = true
	objRegex.Global = true
	strReturn = objRegex.Replace(strHtml, "<a href=""$1"" rel = ""nofollow"" target = ""_blank"">$1</a>")
	set objRegex = nothing
	aspTwitterAutolink = strReturn
end function

'********************************
'* Params assignment
'* arrParams : array -> key_1=val_1, key_2=val_2 
'********************************
private sub aspTwitterSetParams(arrParams)
	m_ObjParams.removeAll
	if isArray(arrParams) then
		Dim tmpParam
		for each i in arrParams
			tmpParam = split(i,"=")
			if Ubound(tmpParam) = 1 then
				m_ObjParams.Add tmpParam(0),tmpParam(1)
			end if
		next
	end if
end sub	

'********************************
'* Check Error Status Message
'* param: [xml: twitter response]
'********************************
private function aspTwitterCheckError(strXmlResponse)
	Dim strErrorMsg:strErrorMsg  = ""
	' personalize error message
	select case m_IntHttpStatus
		case 400
			strErrorMsg = "Bad Request: The request was invalid. " & _ 
						  "It is may caused by bad internet connection or " & _ 
						  "<a href=""http://apiwiki.twitter.com/Rate-limiting"" target=""_blank"">Twitter's rate limiting</a>"
		case 401 
			strErrorMsg = "Not Authorized: Authentication credentials were missing or incorrect. Check your username & password"
		case 403 
			strErrorMsg = "Forbidden: The request has been refused by twitter's server"
		case 404 
			strErrorMsg = "The URL requested is invalid or the resource requested, such as a user, does not exists."	
		case 406 
			strErrorMsg = "Not Acceptable: Invalid data format requested, check your data format option."
		case 500 
			strErrorMsg = "Internal Server Error: Something is broken.  Please <a href=""http://apiwiki.twitter.com/Support"">post to the group</a> so the Twitter team can investigate."
		case 502
			strErrorMsg = "Bad Gateway: Twitter is down or being upgraded."
		case 503
			strErrorMsg = "Service Unavailable: The Twitter servers are overloaded with requests. Try again later."
		case else
			if Len(strXmlResponse) > 0 then
				Dim objXmlDom:set objXmlDom = Server.CreateObject("Microsoft.XMLDOM")
				objXmlDom.async = false
				objXmlDom.loadxml(strXmlResponse)
				objXmlDom.setProperty "SelectionLanguage", "XPath"

				Dim objSingleNode
				Set objSingleNode = objXmlDom.selectSingleNode("//hash/error")
				if not objSingleNode is nothing then
					strErrorMsg= objSingleNode.Text
				end if
				Set objXmlDom = Nothing
			else	
				strErrorMsg  = "There was no data to return."
			end if
	end select
	aspTwitterCheckError = strErrorMsg
end function

'********************************
'* instance initialization
'********************************
sub class_initialize()
	m_StrFormat = "xml"
	call createServerObject
	call aspTwitterShortUrlInit(false,false,false)
end sub

'********************************
'* instance termination
'********************************
sub class_terminate()
	call destroyServerObject
end sub

'********************************
'* verify your cridentials
'********************************
public sub aspTwitterVerifyCredentials()
	Dim strApiUrl:strApiUrl = "http://twitter.com/account/verify_credentials."&m_StrFormat
	Dim strXmlReturn:strXmlReturn = aspTwitterCall(strApiUrl,true,false)
	response.Write(strXmlReturn)
end sub

'********************************
'* Write Error Status
'********************************
public sub aspTwitterWriteError(strBefore,strAfter)
	if len(strBefore) = 0 then strBefore = "<p class=""error"">"
	if len(strAfter) = 0 then strAfter = "</p>"
	Response.Write strBefore&m_StrErrorMessage&strAfter
end sub

'********************************
'* Shorten Url Initialization
'* params: [string:provider], [string:user login], [string:api key]
'********************************
public sub aspTwitterShortUrlInit(strProvider,strUser,strApi)
	if not isObject(m_ObjUrl) then Set m_ObjUrl= new ATLShortUrl
	m_ObjUrl.aspSetProvider = strProvider
	m_ObjUrl.aspSetUser = strUser
	m_ObjUrl.aspSetApi = strApi
end sub

'********************************
'* Shorten Url execution
'* params: [string:long url]
'********************************
public function aspTwitterShortUrlGet(strUrl)
	if Len(strUrl) > 0 then 
		aspTwitterShortUrlGet = m_ObjUrl.aspShortUrlExec(strUrl)
	end if
end function

'********************************
'* Get User Detail
'* Return : Dictionary Object
'* Ref : http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-users show
'********************************
public function aspTwitterUserDetail()
	Dim strApiUrl:strApiUrl = "http://twitter.com/users/show."&m_StrFormat
	call aspTwitterSetParams(array("id="&m_StrUser))
	Dim xmlResult:xmlResult = aspTwitterCall(strApiUrl,false,false)
	Dim objDictionary:Set objDictionary = Server.CreateObject("Scripting.Dictionary")
	if Len(xmlResult)>0 then
		Dim objXmlDom
		set objXmlDom = Server.CreateObject("Microsoft.XMLDOM")
		objXmlDom.async = false
		objXmlDom.loadxml(xmlResult)
		objXmlDom.setProperty "SelectionLanguage", "XPath"

		Dim objRootNode,strNode
		Set objRootNode = objXmlDom.documentElement
		For Each strNode In objRootNode.childNodes 
			if not strNode.nodeName = "status" then
				objDictionary.Add strNode.nodeName,strNode.text
			end if
		Next
		Set objRootNode = nothing
		Set objXmlDom = nothing
	End if
	Set aspTwitterUserDetail = objDictionary
	Set objDictionary = Nothing
end function


'********************************
'* Get User Timeline
'* Return : Array(array(date_1,text_1,source_1,reply_screen_name_1),array(date_2,text_2,source_2,reply_screen_name_2))
'* ref : http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses-user_timeline
'********************************
public function aspTwitterGetUserTimeline()
	Dim strApiUrl:strApiUrl = "http://twitter.com/statuses/user_timeline."&m_StrFormat
	call aspTwitterSetParams(array("id="&m_StrUser))
	Dim strXmlReturn:strXmlReturn = aspTwitterCall(strApiUrl,false,false)
	if Len(strXmlReturn) > 0 then strXmlReturn=aspTwitterFormatXml(strXmlReturn)
	aspTwitterGetUserTimeline = strXmlReturn
end function

'********************************
'* Get Friends Timeline
'* Return : Array(array(date_1,text_1,source_1,reply_screen_name_1),array(date_2,text_2,source_2,reply_screen_name_2))
'* ref : http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses-friends_timeline
'********************************
public function aspTwitterGetFriendsTimeline(count)
	Dim strApiUrl:strApiUrl = "http://twitter.com/statuses/friends_timeline."&m_StrFormat
	if count > 200 then 
		count = 200
	elseif count < 1 then 
		count = 1
	end if
	call aspTwitterSetParams(array("count="&count))
	Dim strXmlReturn:strXmlReturn = aspTwitterCall(strApiUrl,false,true)
	if Len(strXmlReturn) > 0 then strXmlReturn=aspTwitterFormatXml(strXmlReturn)
	aspTwitterGetFriendsTimeline = strXmlReturn
end function

'********************************
'* Format user timeline
'* param : XML
'* Return : Array(array(date_1,text_1,source_1,reply_screen_name_1),array(date_2,text_2,source_2,reply_screen_name_2))
'* ref : http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses-user_timeline
'********************************
private function aspTwitterFormatXml(strXml)
	Dim objXmlDom:set objXmlDom = Server.CreateObject("Microsoft.XMLDOM")
	With objXmlDom
		.async = false
		.setProperty "SelectionLanguage", "XPath"
		.loadxml(strXml)
	End With

	Dim objRootNode:Set objRootNode = objXmlDom.selectNodes("/statuses/status")

	Dim intCounter:intCounter = 0

	' date,text,source,reply_screen_name,author name, author screen name, author avatar url
	Dim arrUserStatus()

	Dim oStatusesNodes,oUserNodes
	Dim iHolders(7)
	For Each oStatusesNodes in objRootNode
		redim preserve arrUserStatus(intCounter+1)
		iHolders(0) = oStatusesNodes.selectSingleNode("created_at").Text
		iHolders(1) = aspTwitterAutolink(oStatusesNodes.selectSingleNode("text").Text)
		iHolders(2) = oStatusesNodes.selectSingleNode("source").Text
		iHolders(3) = oStatusesNodes.selectSingleNode("in_reply_to_screen_name").Text

		Set oUserNodes = oStatusesNodes.selectSingleNode("user")
		if oUserNodes.hasChildNodes() then
			iHolders(4) = oUserNodes.selectSingleNode("name").Text
			iHolders(5) = oUserNodes.selectSingleNode("screen_name").Text
			iHolders(6) = oUserNodes.selectSingleNode("profile_image_url").Text
		end if
		Set oUserNodes = Nothing

		arrUserStatus(intCounter) = iHolders
		intCounter = intCounter + 1
	Next

	Set objRootNode = Nothing
	Set objXmlDom = Nothing

	aspTwitterFormatXml=arrUserStatus 
end function

'********************************
'* Update User Status
'* strStatus : (string) status
'* Return : XML
'* Ref : http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses%C2%A0update
'********************************
public function aspTwitterUpdateStatus(strStatus)
	Dim strApiUrl:strApiUrl = "http://twitter.com/statuses/update."&m_StrFormat
	Dim arrTmpParams: arrTmpParams = array("status="&strStatus)
	call aspTwitterSetParams(arrTmpParams)
	Dim strXml
	strXml = aspTwitterCall(strApiUrl,true,true)
	Dim objXmlDom:set objXmlDom = Server.CreateObject("Microsoft.XMLDOM")
	With objXmlDom
		.async = false
		.setProperty "SelectionLanguage", "XPath"
		.loadxml(strXml)
	End With

	Dim objSingleNode,intReturnId
	Set objSingleNode = objXmlDom.selectSingleNode("//status/id")
	if not objSingleNode is nothing then
		intReturnId = objSingleNode.Text
	else
		intReturnId = 0
	end if
	Set objXmlDom = Nothing
	aspTwitterUpdateStatus = intReturnId
end function

'********************************
'* Open Remote Page
'* Return : Remote Page Content (XML?)
'********************************
private function aspTwitterCall(strUrl,bolPost,bolLogin)

	Dim strParameters,intTimeout
	intTimeout = 5000
	if isObject(m_ObjParams) then
		for each i in m_ObjParams
			if len(i) > 0 and len(m_ObjParams.Item(i)) > 0 then 
				strParameters = strParameters & "&"&i&"="&server.URLencode(m_ObjParams.Item(i))
			end if
		next
	end if

	m_StrErrorMessage = ""
	m_IntHttpStatus = 200

	if bolPost then
		if bolLogin then
			m_ObjXmlHttp.Open "POST", strUrl, false, m_StrUser, m_StrPassword
			m_ObjXmlHttp.setRequestHeader "Authorization", "Basic " & Base64Encode(m_StrUser&":"&m_StrPassword)
		else
			m_ObjXmlHttp.Open "POST", strUrl, false
		end if

		'm_ObjXmlHttp.setTimeouts intTimeout, intTimeout, intTimeout, intTimeout
		m_ObjXmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
		if len(strParameters) > 0 then 
			strParameters = Mid(strParameters,2)
			m_ObjXmlHttp.Send strParameters
		else
			m_ObjXmlHttp.Send null
		end if
	else
		if len(strParameters) > 0 then 
			strParameters = Mid(strParameters,2)
			Dim intStrPos
			intStrPos = Instr(strUrl, "?")
			if not IsNull(intStrPos) and intStrPos > 0 then 
				strUrl = strUrl & "&"
			else
				strUrl = strUrl & "?"
			end if
			strUrl = strUrl & strParameters
		end if
		if bolLogin then
			m_ObjXmlHttp.Open "GET", strUrl, false, m_StrUser, m_StrPassword
			m_ObjXmlHttp.setRequestHeader "Authorization", "Basic " & Base64Encode(m_StrUser&":"&m_StrPassword)
		else
			m_ObjXmlHttp.Open "GET", strUrl, false
		end if
		'm_ObjXmlHttp.setTimeouts intTimeout, intTimeout, intTimeout, intTimeout
		m_ObjXmlHttp.Send null
	end if

	m_IntHttpStatus = m_ObjXmlHttp.status

	Dim strXmlResponse:strXmlResponse = m_ObjXmlHttp.responseText

	Dim strRequestStatus:strRequestStatus = aspTwitterCheckError(strXmlResponse)
	if Len(strRequestStatus) > 0 then
		m_StrErrorMessage = strRequestStatus
		strXmlResponse = ""
	end if
	aspTwitterCall = strXmlResponse
end function

' Base64 Encoding
' http://www.pstruh.cz/tips/detpg_Base64Encode.htm
' rfc1521
' 2001 Antonin Foller, PSTRUH Software, http://pstruh.cz
Private Function Base64Encode(inData)
  Const Base64 = _
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
  Dim sOut, I

  'For each group of 3 bytes
  For I = 1 To Len(inData) Step 3
	Dim nGroup, pOut

	'Create one long from this 3 bytes.
	nGroup = &H10000 * Asc(Mid(inData, I, 1)) + _
	  &H100 * MyASC(Mid(inData, I + 1, 1)) + _
	  MyASC(Mid(inData, I + 2, 1))

	'Oct splits the long To 8 groups with 3 bits
	nGroup = Oct(nGroup)

	'Add leading zeros
	nGroup = String(8 - Len(nGroup), "0") & nGroup

	'Convert To base64
	pOut = Mid(Base64, CLng("&o" & Mid(nGroup, 1, 2)) + 1, 1) + _
	  Mid(Base64, CLng("&o" & Mid(nGroup, 3, 2)) + 1, 1) + _
	  Mid(Base64, CLng("&o" & Mid(nGroup, 5, 2)) + 1, 1) + _
	  Mid(Base64, CLng("&o" & Mid(nGroup, 7, 2)) + 1, 1)

	'Add the part To OutPut string
	sOut = sOut + pOut

  Next
  Select Case Len(inData) Mod 3
	Case 1: '8 bit final
	  sOut = Left(sOut, Len(sOut) - 2) + "=="
	Case 2: '16 bit final
	  sOut = Left(sOut, Len(sOut) - 1) + "="
  End Select
  Base64Encode = sOut
End Function

Private Function MyASC(OneChar)
  If OneChar = "" Then MyASC = 0 Else MyASC = Asc(OneChar)
End Function

end class
%>

 

atl_short_url.asp

 

<%
'************************************************************************
'* Copyright (c) <2009> Ariel G. Saputra <webmaster@asp.web.id>
'*  this file is part of AspTwitterLib
'*
'*	AspTwitterLib is free software: you can redistribute it and/or modify
'*  it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by
'*  the Free Software Foundation, either version 3 of the License, or
'*  any later version.

'*  This program is distributed in the hope that it will be useful,
'*  but WITHOUT ANY WARRANTY; without even the implied warranty of
'*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'*  GNU General Public License for more details.

'*  You should have received a copy of the GNU General Public License
'*  along with this program.  If not, see <http://www.gnu.org/licenses/>.
'*
'* @TITLE:			ATLShortUrl
'* @PACKAGE:		AspTwitterLib
'* @AUTHOR: 		Ariel G. Saputra <webmaster@asp.web.id>
'* @DESCRIPTION:	Shorten url class, currently support tinyurl, is.gd, bit.ly, hex.io
'* @DATE:			May 15 2009
'* @TODO:			add more short url services
'************************************************************************

class ATLShortUrl

private m_StrProvider,m_StrApiUrl,m_StrUserName,m_StrApiKey

public property let aspSetProvider(strProvider)
	m_StrProvider = Lcase(strProvider)
	select case m_StrProvider
		case "bitly"
			m_StrApiUrl = "http://api.bit.ly/shorten?version=2.0.1&format=xml&longUrl=[:URL:]&login=[:LOGIN:]&apiKey=[:API:]"
		case "isgd"
			m_StrApiUrl = "http://is.gd/api.php?longurl=[:URL:]"
		case "hexio"
			m_StrApiUrl = "http://hex.io/api-create.php?url=[:URL:]"
		case else
			m_StrApiUrl = "http://tinyurl.com/api-create.php?url=[:URL:]"
	end select
end property

public property let aspSetUser(strUser)
	m_StrUserName = strUser
end property

public property let aspSetApi(strApi)
	m_StrApiKey = strApi
end property

sub class_initialize()
	me.aspSetProvider = "tinyurl"
	m_StrUserName = m_StrApiKey = ""
end sub

sub class_terminate()
end sub

private function aspGrabUrl(strUrl)
	select case m_StrProvider
		case "bitly"
			Dim oXmlDom,strGrabUrl
			set oXmlDom = Server.CreateObject("Microsoft.XMLDOM")
			oXmlDom.async = false
			oXmlDom.setProperty "SelectionLanguage", "XPath"
			oXmlDom.loadxml(strUrl)
			strGrabUrl = oXmlDom.selectSingleNode("/bitly/results/nodeKeyVal/shortUrl").Text
			Set oXmlDom = Nothing
			aspGrabUrl = strGrabUrl
		case else
			aspGrabUrl = strUrl
	end select
end function

public function aspShortUrlExec(strUrl)
	if Len(m_StrApiUrl) > 0 then
		Dim oXml,strRealUrl,strShortUrl
		strRealUrl = Replace(m_StrApiUrl, "[:URL:]", strUrl, 1, -1, 1)
		strRealUrl = Replace(strRealUrl, "[:LOGIN:]", m_StrUserName, 1, -1, 1)
		strRealUrl = Replace(strRealUrl, "[:API:]", m_StrApiKey, 1, -1, 1)
		set oXml = Server.CreateObject("Msxml2.ServerXMLHTTP.3.0")
		oXml.Open "GET", strRealUrl, false
		oXml.Send null
		strShortUrl = oXml.responseText
		Set oXml = nothing
		aspShortUrlExec = aspGrabUrl(strShortUrl)
	else
		aspShortUrlExec = false
	end if
end function

end class
%>

 

friends.asp

 

<!--#include file="asp_twitter_lib.asp" -->
<%
Dim oTwitterAPI
set oTwitterAPI = new AspTwitterLib
oTwitterAPI.aspTwitterLoginUser = "xxx"
oTwitterAPI.aspTwitterLoginPass = "xxxxxx"

	Dim arrTimeline,strTimelineError
	arrTimeline = oTwitterAPI.aspTwitterGetFriendsTimeline(5)
	if Len(oTwitterAPI.aspTwitterError) > 0 then
	strTimelineError =  "<p class=""error"">" & _ 
						  "Oops unabled fetching friends statuses : " & _
					      "<cite><small>" & oTwitterAPI.aspTwitterError & "<small></cite></p>"
	end if

		if Len(strTimelineError) > 0 then
			response.write	strTimelineError
		else
			if IsArray(arrTimeline) then
				%><ul><%
				Dim intCounter,strStyle
				intCounter = 0
				for each i in arrTimeline
					if isArray(i) then
						strStyle = ""
						if intCounter MOD 2 = 0 then strStyle = "alt"
						%><li class="<%=strStyle%>"><%=i(1)%><br /><small>
						<%if len(i(5)) > 0 then%><a href="http://twitter.com/<%=i(4)%>" rel="nofollow"><%=i(4)%></a><%end if%>
						posted at <%=i(0)%> from <%=i(2)%></small></li><%

						intCounter = intCounter + 1
					end if
				next
				%></ul><%
			Else
				response.Write "<p>Currently no status update</p>"
			End if
		end if
	%>
<% Set objUserDetail = Nothing:Set oTwitterAPI = Nothing %>

 

update_status.asp

 

<!--#include file="asp_twitter_lib.asp" -->
<%
'*************************************************
'* @ sample of update twitter status with AspTwitterLib
'*************************************************
Dim oTwitterAPI:set oTwitterAPI = new AspTwitterLib
oTwitterAPI.aspTwitterLoginUser = "xxx"
oTwitterAPI.aspTwitterLoginPass = "xxxxxx"
oTwitterAPI.aspTwitterShortUrlInit "bitly","username","api key"

Dim intLastID,strTweets		
strTweets = "text here "&oTwitterAPI.aspTwitterShortUrlGet("http://asp.web.id")
intLastID = oTwitterAPI.aspTwitterUpdateStatus(strTweets)

if Len(oTwitterAPI.aspTwitterError) > 0 then
response.write "Oops error occured: "&oTwitterAPI.aspTwitterError
else
Response.Write "intLastID = " & intLastID
end if

Set oTwitterAPI = nothing
%>

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.