2013-03-10 34 views
0

我想獲取AppleScript中的最新推文。 但是,「狀態」的變量無法保存。 如何存儲推文狀態對象?如何使用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 
+0

你能共享代碼?沒有代碼是不可能的...... – 2013-03-10 09:35:14

+0

對不起,我是問題文本的固定格式。 – 2013-03-10 09:45:46

回答

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 
1

有什麼奇怪與Twitter.app的AppleScript的支持,但如果你只需要得到多個屬性,你可以使用告訴塊或平行分配。

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 
+0

謝謝你非常好的答案! – 2013-03-10 11:13:26