0

So I'm trying to get the latest tweets posted by a user using a PHP script (and caching the results into a text file). I'm using the request https://api.twitter.com/1/statuses/user_timeline.json?count=5&screen_name=google and it's been working fine as a public client, but in order to get better control over my API hit limit I need to authenticate my requests.

I've tried the method shown at https://dev.twitter.com/docs/auth/application-only-auth , but after I successfully connect I get the error "Your credentials do not allow access to this resource" (why ?). So I've tried to use the OAuth method (which looks frighteningly complicated for a hobbyist like me), and downloaded the TwitterOAuth library. But I'm still having trouble connecting ! I put my credentials in the config.php file, but I have no idea where to go from there. The documentation seems to be hinting that I need to manually login to Twitter to authorize the application's connection token... or something. Apparently I need to redirect to some callback URL (what even ?!) and get a short-term connection to enable a long-term connection password which I have to store for later ? What is this madness ?

I was initially under the impression that I could just fetch data from Twitter's RSS feeds but those can't be accessed from scripts for some reason (unlike the Google News RSS feed which fetches just fine). It seems I've gotten myself into something much more complicated than what I signed for. Isn't there an easier (and saner) way of doing this ? Or is nothing decidedly simple ?

I apologize for being such an easily-confused dullard, but my head is spinning.

Thanks !


Edit : after digging around some more I decided to just use PHP curl to fetch the raw page, and then do some Xpath voodoo to get the tweets and the time they were posted at. Of course, this is CPU-intensive, far from stable, and probably not a practice that pleases the folks at Twitter; it also only returns the last 20 tweets (which is thankfully enough for my needs).

However, Cormac Driver's response below about Temboo is certainly a method I'll be investigating next time I need to do something like that.

4

1 回答 1

1

Temboo 提供了一种使用 OAuth 向 Twitter 进行身份验证的简单方法。该过程分为两个步骤:

  1. InitializeOauth. 此步骤返回 Twitter 授权 URL,Twitter 帐户持有人可以访问该 URL 以授予对您的脚本的访问权限。

  2. FinalizeOauth. 此步骤返回您的脚本代表用户向 Twitter API 发出经过身份验证的请求所需的访问令牌。

有关如何在此处使用 PHP 执行此操作的完整详细信息:https ://www.temboo.com/library/Library/Twitter/OAuth/

您可以在此页面上查看 Temboo 如何为 Facebook 处理 OAuth 的示例。提供了 PHP 源代码,它几乎与您为 Twitter 执行相同操作所需的代码相同。

(全面披露:我在 Temboo 工作)

于 2013-04-22T13:31:57.293 回答