开发者

Feasibility: Auto-tweet on Update of a page

开发者 https://www.devze.com 2023-01-15 07:21 出处:网络
On my company\'s website we have a display of 40 100px X 100px images that represent the projects that we have been involved in. We have more like 150 projects, but only 40 are displayed on the homepa

On my company's website we have a display of 40 100px X 100px images that represent the projects that we have been involved in. We have more like 150 projects, but only 40 are displayed on the homepage and the selection of the 40 is random. See Example Here.

We also have an Update page which sorts these 40 projects by the date they were added. See Here.

In both cases the data is pulled from a PHP MySQL database and displayed as so on the website.

We are hoping to get a twitter presence as well as re-developing our website and I was wondering:

Is开发者_如何学JAVA there a way to link twitter to the update page, so when I add a new project to the database, or update an existing project it automatically tweets about the new project?

Thanks in advance


It's definitely possible to do; however, since twitter turned off Basic Auth, you'll need to setup a twitter 'app' that you'll grant access to (oAuth) then use that to post. It adds a bit of complexity, but it shouldn't stop you.

Of course, if your CMS can provide an RSS feed of updates/additions (perhaps based on that update page), you could use one of the many RSS to Twitter posting services.

I'm a big fan of the way you can pick and chose Zend Framework's components, so I'd probably use Zend_Service_Twitter for something like this; however, the concept is similar on any Twitter library (or even just interfacing directly with Twitter, but that seems like unnecessary work).

First - as mentioned - you'll need tosetup an app on Twitter. The developer site should help there. You'll also need to **grant your new app access to the account you'll be posting to, what you need is an oAuth access token.

The access token is used for read/write, you'll use it to setup the Twitter library (again, an example from Zend's documentation, but it should be similar to other libraries):

$twitter = new Zend_Service_Twitter(array(
  'username' => 'johndoe',
  'accessToken' => $token
));

Then use whatever data the CMS provieds to create the 'update' post. Maybe something like this:

$status = "We just updated $projectName, check it out: $projectShortLink";
$response = $twitter->status->update($status);

Of course you'll need to make sure that's under the 140 limit.

It's pretty simple, the real overhead is setting up an 'app' and getting the oAuth token You'll need a simple one time script to request and retrieve the token (Zend's documentation gives examples) Or you could request permission for xAuth, but that seems a bit over the top for your application..

One potential benefit - since you're creating an app, you get to pick the 'via AppName' that's displayed in various clients.

0

精彩评论

暂无评论...
验证码 换一张
取 消