【问题标题】:How to get tweet using AppleScript如何使用 AppleScript 获取推文
【发布时间】:2015-01-12 05:20:06
【问题描述】:

我想获取 AppleScript 中的最新推文。 但是,“状态”变量无法保存。 如何存储推文状态对象?

它正在工作:

tell application "Twitter"
  set tw to text of item 1 of statuses of home timeline of current account
end tell

它不工作:

tell application "Twitter"
  set tw to item 1 of statuses of home timeline of current account
  set txt to text of tw
end tell

【问题讨论】:

  • 你能分享代码吗?没有代码是不可能帮你的……
  • 抱歉,问题文本的格式是固定的。

标签: macos twitter applescript


【解决方案1】:

今天有点晚了,但请看看我的应用程序“Twitter Scripter”在 Mac AppStore 上免费提供。

这是一个不露面的后台应用程序,旨在使从 AppleScript 访问 Twitter API 变得微不足道。它支持 OS X (10.8+) 中的原生 Twitter 支持,因此您无需自己处理任何身份验证。您可以从 twitter API 检索响应作为结构化 AppleScript 记录。

例如:

tell app "Twitter Scripter"
  set myTwitterAccount to item 1 of (available accounts) as string
  -- User timeline: This function retrieves the Tweets for a given user name
  fetch user timeline for username "mousedownsoft" using account myTwitterAccount with excluding replies and including retweets
end

【讨论】:

  • 很遗憾现在已经不存在了,因为 Apple 弃用了 ACAccountTypeIdentifierTwitter
【解决方案2】:

Twitter.app 的 AppleScript 支持有些奇怪,但如果您只需要获取多个属性,则可以使用 tell 块或并行赋值。

tell application "Twitter"
    tell item 1 of statuses of home timeline of current account
        set t to text
        set u to url
        properties
    end tell
    -- set {t, u} to {text, url} of item 1 of statuses of home timeline of current account
end tell

或者您可以改用 API 吗?如果您运行 sudo gem install twitter 并在 dev.twitter.com 注册应用程序,这应该可以工作。

require 'rubygems'
require 'twitter'

Twitter.configure { |config|
    config.consumer_key = ""
    config.consumer_secret = ""
    config.oauth_token = ""
    config.oauth_token_secret = ""
}

p Twitter.home_timeline.first.text
p Twitter.home_timeline.first.inspect

【讨论】:

  • 感谢您的精彩回答!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-10
  • 2019-04-09
  • 2020-09-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多