在Coldfusion服务器上实现monkehTweets [英] Implement monkehTweets on Coldfusion Server

查看:99
本文介绍了在Coldfusion服务器上实现monkehTweets的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继承了一个运行Coldfusion的网站,我想在网站上获得一个twitter Feed。我找到了一个似乎能完成这项工作的工具,我已经使用Twitter注册了我的应用,并且我有我的客户端和OAuth代码。



问题是,我不够熟悉Coldfusion知道什么代码,我需要放在有问题的页面拉动tweets。这是我正在使用的图书馆: https://github.com/coldfumonkeh/monkehTweets



从我可以收集的,我的代码应该看起来像这样:

  < cfinvoke 
component =component_name
method =method_name
returnvariable =return_variable>
< cfinvokeargument name =arg1value =value>
< cfinvokeargument name =arg2value =value>
< / cfinvoke>

不幸的是,我不知道在这些字段中放什么。似乎没有列表的任何地方的参数或你应该放在名称,方法和变量字段。所有我需要的是拉最近的三个tweets。这可能不是在这里的问题的标准格式,但任何帮助从知道Coldfusion的人将非常感谢。非常感谢!

解决方案

我写了一个非常基本的演示来从验证用户的时间表中拉出和显示信息。

你需要从对象实例化开始,你看起来你已经做了:(显然,在 init 方法中添加自己的OAuth / Twitter详细信息) / p>

 < cfset objmonkehTweet = new monkehTweet.com.coldfumonkeh.monkehTweet(
consumerKey ='',
consumerSecret ='',
oauthToken ='',
oauthTokenSecret ='',
userAccountName ='',
parseResults = true
)/>

parseResults 值设置为true会将响应转换为struct您可以在ColdFusion中转储并轻松读取值的XML对象。



接下来,调用 getUserTimeline()方法。如果我们不将任何用户ID或屏幕名称值传递到方法调用,它将访问已验证用户的时间轴:

 < cfset arrStatus = objMonkehTweet.getUserTimeline()/> 

由于没有关于格式发送参数,monkehTweet会返回默认的JSON响应 parseResults 设置为true,将产生一个结构体数组)。



现在我们可以开始创建循环。

$



定义要返回的tweet的最大数量:

 < cfset totalTweets = 3 /> 

谨慎的做法是检查数组的长度结果数):

 < cfif arrayLen(arrStatus)LT totalTweets> 
< cfset totalTweets = arrayLen(arrStatus)/>
< / cfif>

现在定义一个循环,从1开始,最大值为 totalTweet 值:

 < cfoutput> 
< ul>
< cfloop from =1to =#totalTweets#index =tweet>

< cfset status = objMonkehTweet.entify(arrStatus [tweet])/>
< li> #arrStatus [tweet] ['user'] ['name']#:#status#< / li>

< / cfloop>
< / ul>



鸣叫像这样: arrStatus [tweet]
monkehTweet对象包含一个名为 entify 的帮助函数,它会将任何URL,用户提示和标签转换为HTML URL以显示。只需传递tweet对象,它会返回格式化的状态。您还可以直接引用响应中的任何对象,因为我们在这里有用户名值。



要查看返回的内容,最好将整个响应,以便您可以看到可用于在您的显示中访问和使用:

 < cfdump var =#arrStatus #/> 

我希望能帮助您开始运行。


I've inherited a site running Coldfusion, and I'm trying to get a twitter feed on the site. I've found a tool that seems to do the job, and I've registered my app with Twitter and I have my client and OAuth codes.

The problem is that I'm not familiar enough with Coldfusion to know exactly what code I need to put on the page in question to pull the tweets. This is the library I'm using: https://github.com/coldfumonkeh/monkehTweets

From what I can gather, my code should look something like this:

<cfinvoke 
 component = "component_name" 
 method="method_name" 
 returnvariable="return_variable">
 <cfinvokeargument name="arg1" value="value">
 <cfinvokeargument name="arg2" value="value">
</cfinvoke>

Unfortunately I have no idea what to put in any of those fields. There doesn't seem to be a list anywhere of the arguments OR what you should put in the name, method, and variable fields. All I need is to pull three recent tweets. This probably isn't a standard format for questions on here, but any help from someone who knows Coldfusion would be greatly appreciated. Thanks!

解决方案

I have written a very basic demo to pull out and display information from the authenticated user's timeline.

You need to start with the object instantiation, which it appears you have done: (obviously adding your own OAuth / Twitter details to the init method here)

<cfset objmonkehTweet   =   new monkehTweet.com.coldfumonkeh.monkehTweet(
            consumerKey     =   '',
            consumerSecret      =   '',
            oauthToken      =   '',
            oauthTokenSecret    =   '',
            userAccountName     =   '',
            parseResults        =   true
        ) />

Setting the parseResults value to true will convert the response into a struct or XML object that you can dump in ColdFusion and easily read the values.

Next, make a call to the getUserTimeline() method. If we don't pass any user id or screen name values in to the method call, it will access the timeline for the authenticated user:

<cfset arrStatus = objMonkehTweet.getUserTimeline() />

As no parameters were sent in regarding format, monkehTweet will return the default response as JSON (which, with parseResults set to true, will result in an array of structs).

Now we can start creating the loop. This is very basic, but will help you get up and running.

Define the maximum number of tweets to return:

<cfset totalTweets = 3 />

It's prudent to then check the length of the array (just in case we have less than the desired maximum number of results):

<cfif arrayLen(arrStatus) LT totalTweets>
    <cfset totalTweets = arrayLen(arrStatus) />
</cfif>

Now define a loop, starting at 1 with a maximum of the totalTweet value:

<cfoutput>
<ul>
<cfloop from="1" to="#totalTweets#" index="tweet">

    <cfset status = objMonkehTweet.entify(arrStatus[tweet]) />      
    <li>#arrStatus[tweet]['user']['name']#: #status#</li>

</cfloop>
</ul>

You can now access each specific tweet like so: arrStatus[tweet]. The monkehTweet object contains a helper function called entify which will convert any URLs, user mentions and hashtags into HTML URLs for display. Simply pass in the tweet object and it will return the formatted status for you. You can also reference any object within the response directly, as we have here with the user name value.

To see what is being returned, it's always best to dump out the entire response so that you can see what is available to access and use in your display:

<cfdump var="#arrStatus#" />

I hope that helps get you up and running.

这篇关于在Coldfusion服务器上实现monkehTweets的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆