What's the best way to use the Twitter API via PHP?

前端 未结 6 1910
梦如初夏
梦如初夏 2021-01-12 16:58

A client would like me to add their Twitter stream to their website homepage, using a custom solution built in PHP.

The Twitter API obviously has a limited number of

6条回答
  •  说谎
    说谎 (楼主)
    2021-01-12 17:38

    1. a cron job (not likley - if there's not even a database, then there are no cron jobs)
    2. write the microtime() to a file. on a page view compare the current timestamp to the saved one. its the difference greater than N minutes, pull the new tweetfeed and write the current timestamp to the file
    3. if the front page is a static html-file not calling any php, include an image that returns an 1px transparent gif (at least you did it this way when i was young) and does your twitter-pulling silently

    or do you mean local-local filesystem, as in "my/the customers computer not the server"-local?

    in this case:

    1. get some server with a cron job or scheduler and PHP
    2. write a script that reads and saves the feed to a file
    3. write the file to the customers server using FTP
    4. display the feed using javascript (yes, ajax also works with static files as datasources). jquery or some lib is great for this
    5. or: create the tweet-displaying html file locally and upload it (but be careful ... because you may overwrite updates on the server)

    imo: for small sites you often just don't need a fully grown sql database anyway. filesystems are great. a combination of scandir, preg_match and carefully chosen file names are often good enough.
    and you can actually do a lot of front-end processing (like displaying XML) using beautiful javascript.

提交回复
热议问题