Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Tenho uma página ASP
gostaria de fazer como este blog
http://www.brainstorm9.com.br/
alguém poderia me ajudar, como trazer o último post no twitter na página ASP?
Por que estou montando um site para o cliente, e ele quer que seja resgatado sempre o último post do twitter deles e que traga direto no site
já revirei o google e tudo mais inclusive o forum, achei como trazer informações do usuário neste post
mas quero trazer o último post, como fazer?
Obrigado pela ajuda que sempre dão =)
/////////////////////////////////// EDITADO
hmm legal
consegui fazer quase seguindo as instruções deste tópico feito pelo patrike.
a dúvida agora é, como trazer apenas o ÚLTIMO tweet?
Alguém pode ajudar? Obrigado.
////////////////////////// EDIT
Pronto consegui apenas mudei uma linha para
if IsArray(arrTimeline) then
Dim intCounter,strStyle
intCounter = 0
contador = 1
for each i in arrTimeline
if isArray(i) then
strStyle = ""
if intCounter MOD 2 = 0 then strStyle = "alt"
if contador = 1 then
response.Write(i(1))
contador = contador + 1
end if
intCounter = intCounter
end if
next
Else
response.Write ""
End if
olha esta 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]
'********************************
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]
'********************************
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)
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]
'********************************
end function
'********************************
'* Obter Detalhes do usuário
'* Retorno : Dictionary Object
'* Ref : http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-users show
'********************************
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
'********************************
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
'********************************
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)
end sub
'********************************
'*Abrir página remota
'* Retorno: Conteúdo da página Remoto (XML?)
'********************************
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)
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 function end functionend sub
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
else
Dim arrTimeline,strTimelineError
arrTimeline = oTwitterAPI.aspTwitterGetUserTimeline()
if Len(oTwitterAPI.aspTwitterError) > 0 then
end if
%>
<% 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
else
Dim arrTimeline,strTimelineError
arrTimeline = oTwitterAPI.aspTwitterGetUserTimeline()
if Len(oTwitterAPI.aspTwitterError) > 0 then
end if
%>
<% 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]
'********************************
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]
'********************************
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)
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]
'********************************
end function
'********************************
'* Get User Detail
'* Return : Dictionary Object
'* Ref : http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-users show
'********************************
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
'********************************
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
'********************************
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
'********************************
end function
'********************************
'* Update User Status
'* strStatus : (string) status
'* Return : XML
'* Ref : http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses%C2%A0update
'********************************
end function
'********************************
'* Open Remote Page
'* Return : Remote Page Content (XML?)
'********************************
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
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)
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 function end functionend sub
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
<% 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
%>