In this blog post I'm going to a explain how you can use the Twitter API in a CakePHP application using webservices.
The implementation of the Twitter API is provided by our Twitter webservices plugin. It not only supports the regular API methods but even allows you to use their statuses streaming API.
To start you will need to install the plugin using Composer:
composer require cvo-technologies/cakephp-twitter
This will automatically install the Webservices plugin which provides the integration with CakePHP.
Now you will need to enable the two plugins. If you're already using a webservice implementation in your project then you will only need to load our Twitter implementation and not the Webservice plugin itself.
bin/cake plugin load Muffin/Webservices --bootstrap
bin/cake plugin load CvoTechnologies/Twitter
Add the following to your
Datasources section of your application's config.
Make sure to change the
oauthSecret can be left empty.
This is how you can use the implementation in a controller.
In this blogpost I'll explain how to set up a Croogo 3 development environment
composer create-project cakephp/app croogo-app --stability dev --prefer-source
composer.json you need to make the following changes:
composer require croogo/croogo 3.0.*@dev
post-autoload-dumpso it includes the Croogo ComposerInstaller:
The next thing we'll need to do is configure CakePHP. This involves loading the necessary plugins and setting up a database.
bin/cake plugin load Acl --bootstrap
bin/cake plugin load Croogo/Core --bootstrap --routes
Now you'll have to configure the database for Croogo. This can be done in the applications
Your application has a default route to
routes.php in the
config directory. Comment it out so that you can use Croogo's base route.
Create a settings file in
settings.json with the following content:
You should be able to access Croogo using your webserver. Croogo's source code can be found in
Your username will be croogo, your password will be croogo as well
If you've got any questions or suggestions leave a comment
We've been working on adding support for ORM like querying of data to the CakePHP Webservice plugin by UseMuffin. This allows you to work with webservices in the quick, easy and familiar way you're used to in CakePHP without having to dive into the details of a particular web API.
In this post I'll be explaining the parts of the ORM for webservices and what they're being used for.
Below is the folder structure that the ORM expects parts to be in. This applies to CakePHP applications and plugins.
The first and most important part is the
Webservice. Its the bridge between the ORM and the actual API you're calling. This class is being called by the
Query when data needs to be read from the service.
When data needs to be queried the
Query will call the execute method which will go out to the API and fetch the necessary data. That data will then be parsed and formatted by the
Webservice. When done it will return a
ResultSet containing a set of
Resources and the total number of results available (this will for example be used for pagination).
In the example below we create a
Webservice to fetch articles from a webservice at example.com. Here you can see the articles being turned into a set of
Resources and being returned by the
The next part is the
Endpoint, its essentially the
Table equivalent of webservice ORM. This is what you use to get data out from your webservice using the ORM. For a comprehensive guide to
Endpoints you can check out the CakePHP documentation about
The following methods are currently implemented in the base
This list will increase in size as the ORM continues to be improved. This list will eventually be removed once the webservices ORM is on par with the CakePHP ORM.
Down here is an example of an
Endpoint to get articles fromt the
Webservice shown in the previous example. Note that it sets the
Webservice which it gets from the
Driver that'll have to create as well. For a post to get you started with a
Driver check out this post by David Yell.
The last part is the
Resource, this represents the actual results returned by the API.
The example below the
Resource represents the articles returned when doing a find using on the
If you want some more information feel free to comment on this post.