<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>
<channel>
	<title>Raymond Kolbe &#187; api</title>
	<atom:link href="http://www.raymondkolbe.com/tag/api/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.raymondkolbe.com</link>
	<description>Code, cars, and beer...</description>
	<lastBuildDate>Sun, 07 Feb 2010 17:14:18 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Zend, Twitter, and OAuth Made Easy</title>
		<link>http://www.raymondkolbe.com/2009/10/03/zend-twitter-and-oauth-made-easy/</link>
		<comments>http://www.raymondkolbe.com/2009/10/03/zend-twitter-and-oauth-made-easy/#comments</comments>
		<pubDate>Sat, 03 Oct 2009 23:24:50 +0000</pubDate>
		<dc:creator>Ray</dc:creator>
				<category><![CDATA[Computer Related]]></category>
		<category><![CDATA[PHP/MySQL]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[zend]]></category>
		<guid isPermaLink="false">http://white-box.us/?p=398</guid>
		<description><![CDATA[I have been working on a Twitter service as of late and ran into a problem that I am sure others have as well and ended up solving it in their own way.  However, after searching high and low on the Internet for an elegant solution, I came up with nothing and found I [...]]]></description>
			<content:encoded><![CDATA[<p>I have been working on a Twitter service as of late and ran into a problem that I am sure others have as well and ended up solving it in their own way.  However, after searching high and low on the Internet for an elegant solution, I came up with nothing and found I was on my own.  This post is for those of you who are, or will be, using Zend_Service_Twitter and need Twitter users to grant your application access to their account information in a secure way.</p>
<p>The project I am working on requires that users allow my Twitter service to access their account information.  The only reason I require this is because this service makes several API requests over the course of time, and instead of having users use up all of my allotted API service requests, I use their&#8217;s instead,  It&#8217;s a little more complicated than that, and a full explanation falls outside the scope of this post.  All you need to keep in mind for this post is that I need to have access to their account so API calls are counted on their behalf and not my server&#8217;s.</p>
<p>Currently, Zend Framework 1.9 only supports basic authentication for the Twitter API, which works well, but leaves, or should leave, a bad taste in the end-user&#8217;s and developer&#8217;s mouth.  I say this because a developer who wants access to a user&#8217;s account at a later time (e.g. if you are running scheduled API calls) will have to store the user&#8217;s credentials on the server.  This means A) the user may be iffy about using your service since they may not trust your site and/or want their password stored on your server, and B) this creates more overhead for you because you now have to keep track of user information, keep it secure, etc.  The way we get rid of this bad taste is to implement a system such as OAuth.</p>
<p>OAuth is an authentication protocol that allows secure API authorization for applications.  What this means is that a user can grant you, the 3rd party developer, access to their information without providing you with their username and password.  User login takes place at the source, in this case at Twitter.com.  For more information about OAuth, please see the <a href="http://apiwiki.twitter.com/OAuth-FAQ">Twitter API Wiki / OAuth FAQ</a></p>
<p>If you are currently using the Twitter API, it is probably better to change over to using OAuth sooner than later since support for basic authentication will be going away in the future.</p>
<p>In order to get Zend_Service_Twitter working with OAuth, you will need to obtain OAuth via subversion since it is not in the currently released version of Zend Framework.  It can be obtained <a href="http://framework.zend.com/svn/framework/standard/incubator/library/Zend/Oauth/">here</a>.</p>
<p>The code you are about the see takes place in my IndexController, meaning I am using Zend&#8217;s MVC setup.  I have also put configuration information inline so you can see exactly what is passed into each object.</p>
<pre class="brush: php;">
&lt;?php
/**
 * Default Index Controller using Zend's MVC implementation.
 *
 * @author Raymond J. Kolbe &lt;rkolbe@white-box.us&gt;
 */
class IndexController extends Zend_Controller_Action
{
    /**
     * Login Action
     *
     * Performs user login through Twitter using OAuth.  If user's have not
     * granted our application access to their account, they will be sent to
     * Twitter to do so.  Once done, they will return to this page again so
     * that we can handle them (e.g. run our application for them).
     *
     * @param void
     * @return void
     */
    public function loginAction()
    {
        // Check to see if the user already has an OAuth access token
        if ($this-&gt;_session-&gt;access_token) {
            // You would redirect the user to the main part of your
            // application that they needed to be authenticated for.
        }
        // Configuration for OAuth. @see Zend_Oauth_Consumer
        $config = array(
            'signatureMethod' =&gt; 'HMAC-SHA1',
            'callbackUrl' =&gt; 'http://localhost/login',
            'requestTokenUrl' =&gt; 'http://twitter.com/oauth/request_token',
            'authorizeUrl' =&gt; 'http://twitter.com/oauth/authorize',
            'accessTokenUrl' =&gt; 'http://twitter.com/oauth/access_token',
            'consumerKey' =&gt; 'jDrJud90Jhg66whddj876',
            'consumerSecret' =&gt; 'UdjneHdyGsj90Bsg2UdjneHdyGsj90Bsg2'
        );
        $consumer = new Zend_Oauth_Consumer($config);
        // If we do not have a request token, generate one now
        if (!$this-&gt;_session-&gt;request_token) {
            $request_token = $consumer-&gt;getRequestToken();
            // Save the token for when the user returns to this page.
            // This will be used to get the user's access token.
            $this-&gt;_session-&gt;request_token = serialize($request_token);
            // Send the user off to Twitter to grant our application access
            $consumer-&gt;redirect();
            return;
        }
        // If we made it here, the user has been to Twitter to grant our
        // application access and now we must get an access token that
        // will allow us to make API calls on behalf of the user.
        $access_token = $consumer-&gt;getAccessToken($this-&gt;_request-&gt;getQuery(), unserialize($this-&gt;_session-&gt;request_token));
        // We no longer need the request token so remove it
        unset($this-&gt;_session-&gt;request_token);
        // Save to session so that reloading of this page will send the user
        // to your application main page or wherever you want them to go.
        $this-&gt;_session-&gt;access_token = serialize($access_token);
        // This line is very important. Since Zend_Service_Twitter does
        // not have support for OAuth (yet), this is how we get it to work.
        // All we are doing is making Zend_Service_Twitter use OAuth's
        // HTTP Client instance, which will automatically append the proper
        // OAuth query info to any Twitter service call we make from here
        // on out.
        Zend_Service_Twitter::setHttpClient($access_token-&gt;getHttpClient($config));
        // Username and password are passed in as null because we will not be
        // authenticating using a user/pass combo (which uses basic
        // authentication).
        $twitter = new Zend_Service_Twitter(null, null);
        // This is not required but shows you as an example that OAuth did
        // in fact work.
        $response = $twitter-&gt;account-&gt;verifyCredentials();
        // Your code goes here.  This would be the point you want to save
        // the access token to the database for later use and/or save a cookie
        // on the user's system.
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.raymondkolbe.com/2009/10/03/zend-twitter-and-oauth-made-easy/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Table view helper it out!</title>
		<link>http://www.raymondkolbe.com/2009/07/25/table-view-helper-it-out/</link>
		<comments>http://www.raymondkolbe.com/2009/07/25/table-view-helper-it-out/#comments</comments>
		<pubDate>Sat, 25 Jul 2009 17:00:15 +0000</pubDate>
		<dc:creator>Ray</dc:creator>
				<category><![CDATA[Cookbook]]></category>
		<category><![CDATA[PHP/MySQL]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[helper]]></category>
		<category><![CDATA[php]]></category>
		<guid isPermaLink="false">http://white-box.us/?p=390</guid>
		<description><![CDATA[Table view helper has been released!  Since my last post about writing a helper such as this, a lot has changed.  I hope to have API docs up soon. In the meantime you can download the code and check out the examples at its new project page.
]]></description>
			<content:encoded><![CDATA[<p>Table view helper has been released!  Since my last post about writing a helper such as this, a lot has changed.  I hope to have API docs up soon. In the meantime you can download the code and check out the examples at its new <a href="projects/table/">project page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.raymondkolbe.com/2009/07/25/table-view-helper-it-out/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dropbox API</title>
		<link>http://www.raymondkolbe.com/2009/05/29/dropbox-api/</link>
		<comments>http://www.raymondkolbe.com/2009/05/29/dropbox-api/#comments</comments>
		<pubDate>Sat, 30 May 2009 02:37:01 +0000</pubDate>
		<dc:creator>Ray</dc:creator>
				<category><![CDATA[Computer Related]]></category>
		<category><![CDATA[PHP/MySQL]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[dropbox]]></category>
		<category><![CDATA[php]]></category>
		<guid isPermaLink="false">http://white-box.us/?p=271</guid>
		<description><![CDATA[http://code.google.com/p/dropbox-api/
A while back (3 or 4 months) I emailed the guys over at Dropbox asking them about a public API.  The response I got was basically that in the near future they will have something.  I want it now!!  Guess I will have to keep tabs on that Google Group (link above).
]]></description>
			<content:encoded><![CDATA[<p><a href="http://code.google.com/p/dropbox-api/">http://code.google.com/p/dropbox-api/</a></p>
<p>A while back (3 or 4 months) I emailed the guys over at Dropbox asking them about a public API.  The response I got was basically that in the near future they will have something.  I want it now!!  Guess I will have to keep tabs on that Google Group (link above).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.raymondkolbe.com/2009/05/29/dropbox-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
