Feature: Auto-tweet when refreshing page

On my company website, we display 40 100px X 100px images that represent the projects in which we participated. We have more than 150 projects, but only 40 are displayed on the main page, and the choice of 40 is random. See an example here .

We also have an update page that sorts these 40 projects by the date they are added. See here .

In both cases, data is retrieved from the PHP MySQL database and displayed on the website in the same way.

We hope to gain a Twitter presence, as well as rethink our site, and I was wondering:

Is 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 reports a new project?

Thank you in advance

+4
source share
1 answer

It is definitely possible to do ; however, since Twitter turned off Basic Auth, you need to configure the twitter application you grant access to (oAuth), then use it to publish. This adds a bit of complexity, but it should not stop you.

Of course, if your CMS can provide an RSS feed for updates / additions (perhaps based on this update page), you can use one of many RSS feeds to post on Twitter. .

I am a big fan of how you can select and select Zend Framework components, so I would probably use Zend_Service_Twitter for something like that; however, the concept is similar to any Twitter library (or even just interacts directly with Twitter, but this seems like unnecessary work).

First - as already mentioned - you need to set up the application on Twitter. the developer's site should help there. You will also need to provide your new application with access to the account you will be hosting, what you need is the oAuth access token.

The access token is used for reading / writing, you will use it to configure the Twitter library (again, an example from the Zend documentation, but it should look like other libraries):

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

Then use any data provided by the CMS to create the “update”. Maybe something like this:

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

Of course, you need to make sure that it is under the limit of 140.

It's pretty simple, the real overhead is creating an “application” and getting an oAuth token. You will need a simple one-time script to request and receive a token (examples are provided in the Zend documentation). Or you can request permission for xAuth , but this is a bit like the top for your application.

One potential advantage is that since you are creating an application, you can choose "through AppName" to be displayed on different clients.

+3
source

All Articles