Coder Social home page Coder Social logo

micmania1-sstwitter's Introduction

SSTwitter

SSTwitter is a Silverstripe module to allow simple integration between Twitter & Silverstripe.

Features

  • CMS interface to integrate Silverstripe with a Twitter application & connect an account to the website.
  • Connect/Disconnect Member's to Twitter accounts.
  • Enable/Disable Twitter login through the CMS.
  • Developer Access to Twitter API through PHPTwitter.

Usage

$TwitterConnectURL (TwitterApp::connect_url()) This displays a link where a logged in user will be taken through the Twitter authentication process to connect their Twitter account.

$TwitterDisconnectURL (TwitterApp::disconnect_url()) This will disassociate the Twitter account from the Member.

$TwitterLoginURL (TwitterApp::login_url()) This will return a url whereby the user can login to their Silverstripe account through Twitter where previously connected.

<a href="$TwitterConnectURL">Connect</a><br />
<a href="$TwitterDisconnectURL">Disconnect</a><br />
<% if TwitterLoginURL %>
	<a href="$TwitterLoginURL">Login</a>
<% else %>
	Twitter Login is disabled.
<% end_if %>

Extending

SSTwitter uses PHPTwitter for its Twitter Authentication which has a central Twitter->api() method which handles all API requests. This means you can easily harness its power to interact directly with Twitter. Below is an example of how you would get the latest tweets for the account connected to your website.

In Page_Controller.php:

public function LatestTweets($count = 3) {

	$tweets = new ArrayList();

    $twitterApp = TwitterApp::get()->first();
	$twitter = $twitterApp->getTwitter(); // Access the PHPTwitter interface
	$twitter->setAccess(new OauthToken($twitterApp->TwitterAccessToken, $twitterApp->TwitterAccessSecret));

	// Get the latest Tweets
	if($twitter->hasAccess()) {
	    $result = $twitter->api("1.1/statuses/user_timeline.json", "GET", array(
	        "screen_name" => $twitterApp->TwitterScreenName,
	        "count" => (int) $count
	    ));
	    
	    if($result->statusCode() == 200) {
	    	$json = json_decode($result->body(), true);
	    	if(count($json) > 0) {
	    		foreach($json as $tweet) {
	    			$tweets->push(ArrayData::create(array(
	    				"Tweet" => $tweet['text'],
	    				"Created" => $tweet['created_at'],
	    				"Link" => "http://www.twitter.com/".rawurlencode($tweet['user']['screen_name'])."/status/".rawurlencode($tweet['id_str'])
	    			)));
	    		}
	    	}
	    }
	}
	return $tweets;
}

In Page.ss

<% if LatestTweets %>
	<ul>
		<% loop LatestTweets %>
			<li>$Tweet - <a href="$Link">$Created</a></li>
		<% end_loop %>
	</ul>
<% end_if %>

micmania1-sstwitter's People

Contributors

micmania1 avatar lefters avatar

Watchers

James Cloos avatar helpfulrobot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.