Contents
Share Your Experience: YouTube Integration In Games
 
 
Printer-Friendly VersionPrinter-Friendly Version
 


Part of:



[More information...]
 

Latest News
spacer View All spacer
 
November 22, 2009
 
Video Game Watchdog National Institute On Media And The Family Shutting Down [11]
 
Modern Warfare 2 Infinity Ward's 'Most Successful PC Version' Yet [12]
 
New Tech, Design Details Of Project Natal To Emerge At Gamefest In February
spacer
Latest Jobs
spacer View All     Post a Job     RSS spacer
 
November 22, 2009
 
Sucker Punch Productions
Character Artist
 
Sucker Punch Productions
3D Environment Artist
 
Sucker Punch Productions
Network Programmer
 
Sucker Punch Productions
Texture Artist
 
Sony Online Entertainment
Brand Manager
 
Monolith Productions
Sr. Software Engineer, Engine - Monolith Productions - #113767
 
Crystal Dynamics
Sr. Level Designer
 
Gargantuan Studios
Lead World Designer
spacer
Latest Features
spacer View All spacer
 
November 22, 2009
 
arrow Upping The Craft: Susan O'Connor On Games Writing [6]
 
arrow Small Developers: Minimizing Risks in Large Productions - Part II [6]
 
arrow iPhone Piracy: The Inside Story [48]
 
arrow And Yet It Grows: Analyzing the Size and Growth of the European Game Market [5]
 
arrow NPD: Behind the Numbers, October 2009 [13]
 
arrow Reflecting On Uncharted 2: How They Did It [5]
 
arrow Sponsored Feature: Rasterization on Larrabee -- Adaptive Rasterization Helps Boost Efficiency
 
arrow Postmortem: Wadjet Eye's The Blackwell Convergence [2]
spacer
Latest Blogs
spacer View All     Post     RSS spacer
 
November 22, 2009
 
Accepting the Inherent Value of Games
 
Planckogenesis, Part II: Song Structure & Gravy Train [1]
 
Designing Games Is About Matching Personalities [1]
spacer
About
spacer News Director:
Leigh Alexander
Features Director:
Christian Nutt
Editor At Large:
Chris Remo
Advertising:
John 'Malik' Watson
Recruitment/Education:
Gina Gross
 
Features
  Share Your Experience: YouTube Integration In Games
by Claus Höfele
1 comments
Share RSS
 
 
November 22, 2008 Article Start Previous Page 3 of 4 Next
 

Implementing a YouTube Request

The principle of a RESTful service is captured in the following class function template:

template<class RequestOperator, class ResponseOperator>
YouTubeServiceState YouTubeService::service(
RequestOperator requestOperator, const typename RequestOperator::Input& input,
ResponseOperator responseOperator, typename ResponseOperator::Output& output)
{
const bool developerKeyValid = !m_DeveloperKey.empty();
const bool authenticationValid =
!RequestOperator::requiresAuthentication || !m_AuthenticationToken.empty();

ASSERT_M(authenticationValid, "Authentication required for this service.");
ASSERT_M(developerKeyValid, "Developer key required.");

YouTubeServiceState result = YouTubeServiceStates::Ok;
if (authenticationValid && developerKeyValid)
{
m_WriteBuffer.clear();
result = requestOperator(m_CurlHandle, input, m_ClientId, m_DeveloperKey,
m_AuthenticationToken);
if (result == YouTubeServiceStates::Ok)
{
result = responseOperator(m_WriteBuffer, output);
}
}

return result;
}

This is C++'s way of saying: “First check that the application has a developer key. If the request requires authentication, also check that the application is authenticated. Then, perform the HTTP request implemented in the request operator and have the answer parsed by the implementation of the response operator.”

The method is templated with request and response operators because I wanted to separate the algorithm to perform a service from the details of a specific request. This allows me to add more requests as I need them by implementing additional operators with the required interface signature (functors as they are called in C++):

struct Request
{
typedef ... Input; ///< Input type.
enum { requiresAuthentication = false };

/** Performs a request.*/
YouTubeServiceState operator()(
CURL* curlHandle, const Input& input,
const std::string& clientId, const std::string& developerKey,
const std::string& authenticationToken);
};

struct Response
{
typedef ... Output; ///< Output type.

/** Parses a response. */
YouTubeServiceState operator()(
const std::string& response, Output& output);
};

Whereas the request functor is responsible to call a service based on the given input data, the response functor parses the result into an output object. In my demo, I'm using libcurl for sending HTTP requests and TinyXML for parsing the response.

The request functor can also require authentication if requiresAuthentication is set to true in the functor's declaration. Not all requests need to be authenticated, but when sending videos on behalf of a YouTube user, you'll first need to send one request with the user's name and password to get an authentication token.

In another request, you include this token to actually perform the upload. This sequence is illustrated in Figure 3.

Figure 3: Uploading a video to YouTube requires authentication.

The authentication request has to be sent via HTTPS so that eavesdroppers can't spy on the YouTube password. For this reason, I have configured libcurl to use OpenSSL, which takes care of verifying YouTube's server and encrypting the authentication request.

 
Article Start Previous Page 3 of 4 Next
 
Comments

Bryson Whiteman
profile image
This article made a light-bulb appear above my head. I haven't been hip to games making use of this You-Tube API. It sounds like it would be possible to even make a Flash game that you can upload footage from using these, or similar techniques. It might require some server-side scripts to encode video but I think it'd be possible.

I'm going to look into it.


none
 
Comment:
 


Submit Comment