This QuickStart will walk you through the basics of accessing the NewsCred Platform API using the NewsCred Drupal 5 modules. Let's get started!
Note: These modules are compatible with Drupal 5.
Start by downloading our NewsCred Drupal Modules. Once the download is completed, unzip/untar it and copy the newscred_drupal_0.x/modules/newscred folder to your {drupal_root}/sites/all/modules folder.
Now, copy the template files in the newscred_drupal_0.x/templates folder to your {drupal_root}/themes/{current_theme} folder, where {current_theme} is the name of the theme you're currently using, for example: garland.
You'll need a valid API Access Key to make API calls in production, you can request one here. For development and testing purposes, you can use this API Access Key: c4bcc3f7c9bf9ec159f51da0a86ca658.
The NewsCred Drupal Modules consists of 3 different Drupal modules, here's what they do:
Topic Module - Creates nodes and blocks with topic related content from the NewsCred Platform.
Article Module - Creates nodes and blocks with article related content from the NewsCred Platform.
Category Module - Creates nodes and blocks with category related content from the NewsCred Platform.
Let's set things up by enabling these modules in your Drupal installation. To do this, log in to your Drupal Admin Panel and navigate to Administer > Site Building > Modules.
Under the package NewsCred, select NewsCred Topic, NewsCred Article and NewsCred Category and hit the Save configuration button like so:
If you have a commercial API Access Key, you can open the newscred.key.inc file and add it like this:
define('NEWSCRED_ACCESS_KEY','c4bcc3f7c9bf9ec159f51da0a86ca658');
Now that you're all set up, let's start building a simple NewsCred powered topic page!
Let's create a Barack Obama topic page that displays 20 Obama related articles in the main content area and 5 related topics, 2 related images and 10 related tweets in the right sidebar.
First, some explaining. Every object in the NewsCred Platform, except Category objects, is assigned a globally unique ID called a GUID. For instance, the GUID for the topic "Barack Obama" is 1e3f343e71de57fe9cc70b90c07e196e.
Now, open up the Drupal Admin Panel and navigate to Create content > NewsCred Topic page.
Congrats, you'll now be redirected to your first NewsCred powered topic page! This is what you should see:
Next, let's add some content to the right sidebar. Navigate to Administer > Site building > Blocks.
Once your page is refreshed, the NewsCred Topic - Related Topics block should now be displayed under the Right sidebar section in the table. Click on the configure link next to it.
Check out your Barack Obama topic page now by navigating to Content Management > Content > Barack Obama. You should now see 5 related topics in the right sidebar.
Navigate back to Administer > Site building > Blocks. Let's add 2 related images to the right sidebar.
Once your page is refreshed, the NewsCred Topic - Related Images block should now appear under the Right sidebar section in the table. Click on the configure link next to it.
Navigate to your topic page, you should now see 2 related images below the related topics in the right sidebar.
Navigate back to Administer > Site building > Blocks. Let's add 10 related tweets to the right sidebar.
Once your page is refreshed, the NewsCred Topic - Related Images block should now appear under the Right sidebar section in the table. Click on the configure link next to it.
Navigate to your topic page, you should now see 5 related tweets below the related images in the right sidebar.
That's it! You've just created a NewsCred powered Drupal topic page in a matter of minutes. For more information about which nodes and blocks are supported in the current versions of our NewsCred Drupal Modules see the following sections.
The dynamic pages are the ones in which you pass the topic name as part of the URL (for example http://yourserver.com/topic/[topic-name]). The module than extracts the name from the URL, searches the platform for the topic and creates the page with contents pulled from the platform. No GUID has to be specified. The URL preceding the topic name, which is 'topic' by default, is customizable. And so is the content on the page. You get a form similar to the NewsCred Topic page creation form, which lets you choose what and what not to show on the dynamic page. This is how you can do this
Now in your browser address bar, type http://[host-name]/[url]/[topic-name] or in case you don't have Clean URLs enabled type http://[host-name]/?q=[url]/[topic-name] and hit enter.
If your host is example.com, the preceding URL is 'topic' and the name of the topic itself is Barack Obama, then the full URL is http://example.com/topic/barack-obama or http://example.com/?q=topic/barack-obama
Remember you have to pass the topic name in a slugified form. That is the topic name must be lower cased, with all spaces replaced by '-'.
The optional parameters on content creation form lets you choose what content you want to show on the pages(articles, images, videos etc.). You can also control other criteria such as how many items to show, selecting specific sources for articles, specifying classification for topics and so on.
Content Options
Related Topic Options
Related Article Options
If you are using PHPTemplate as the templating engine of your Drupal installation, the following should be the names of templates
Inside each template you have granular control over the content returned by NewsCred Platform. That's why instead of putting everything in a single $content variable, the modules populate a number of NewsCred objects as properties of the node.
Now if you want to show a list of related articles on the page, with their source and date specified, this is how you can do it in a template
<ul>
<?php foreach($node->articles as $article){ ?>
<li>
<a href="<?php print $article->link ?>">
<?php print $article->title?>
From <?php print $article->source ?>
Dated<?php print date('j F Y', strtotime($article->published_at))?>
</a>
</li>
<php ? } ?>
</ul>
The module has the following blocks that can be enabled and configured in Administer > Site Building > Blocks in the administration panel.