Welcome, guest Sign In

Building Yahoo! Social Applications with Flash

Use the expressiveness and cross-browser goodness that Flash and Flex provide to build a fun and powerful application using the Yahoo! Social APIs on your own website, AIR application, or from within an Open Application.

All code and samples are provided free of charge under a BSD license.

Yahoo Social Applications in Flash

Getting Started

Requirements

To use the ActionScript 3 Social SDK, you'll need:

  • A web server that allows POST requests
  • A means of grabbing POST variables and creating a query string
  • Basic knowledge of ActionScript 3 with Flash or Flex

If you are using YAP and the ActionScript 3 SDK, authorization will effectively be taken care of, so you won't need to learn the details of using OAuth. However, if you wish to handle authorization yourself, you may find the PHP SDK helpful on the server-side.

Creating A New Application

To get started, you'll need to set up a new app and get a consumer key and secret in order to access the Social APIs.

If you are targeting your app to run within YAP, create a new Open Application and use the developer tool to create, preview and deploy your application. For a Flash application you will use this tool along with YML (Yahoo! Markup Language) to embed your application.

Get started by following these steps:

Once you've set up an new application, you'll get the necessary keys you can use for development and testing.

If you are implementing authorization yourself, may also find it helpful to read about OAuth Authorization.

Downloading The Package

The component is distributed with full source code, a Flex 3 SWC, documentation and a Yahoo! styled CSS skin. To use in Flex Builder or Flash CS3, drop the source into your project's 'src' directory. You can also use the single SWC file in Flex Builder by dropping it into your project's 'libs' directory, or point to it in the project build path.

Note: The API uses the open-source JSON utility in as3corelib. For the latest and greatest version of as3corelib, check out the project page.

Version 1.3 - Download

Using the YOS API and Components

This API provides an easy entry point for a Flash or Flex developer, enabling full use of the Yahoo! Social APIs in ActionScript 3. Through this API you are able to create a session, query for friends of a user and get their profile information, all through simple and familiar ActionScript.

Be sure to check out the examples and class reference documentation to get familiar with the API.

Creating a User Session

In order to create a session, you are required to pass an OAuth consumer key / secret and an access token / secret in order to begin a session.

By passing these values along to the YahooSession object, you then can fetch the sessioned user, the object that represents the user viewing the application.

See the section on Authentication for more on this topic.

Alternatively, if your app runs within YAP, you can instantiate a session directly using the user and access token parameters in the flashvars.

Getting User Information

Once you have a YahooUser created, you can then begin making social data requests such as loading profile information and connections.

Getting Friends Data

One of the more popular uses is to display a list of friends, and that's easily accomplished by calling the getConnections method on the user's connections property.

Using YQL

YQL provides a single, straight-forward endpoint for developers to access structured data across Yahoo! and beyond. As part of this SDK, an familiar ActionScript interface is provided to make using YQL that much easier.

If you have a sessioned user, you can query for their social data.

Using the CSS Files in Flex

The skin is provided for you to drop into your Flex applications, giving a slick, standard interface out-of-the-box. All you need to do is add a Style tag to your Flex application, pointing to the yap_ui.css file.

Example CSS Skin

Good Things To Know

Building a Flash Application in YAP

If you are targeting your application on the Yahoo! Application Platform, there a few things to keep in mind as you begin to build your app using Flash. Most importantly, you must use YML to embed your SWF into the app. By default, yml:swf will pass a set of flashvars specifying some environment variables, such as the current app view, viewer and owner GUIDs.

However, when displaying your Flash application in YAP, not all of the required variables are passed through using yml:swf. Therefore, you'll need a way of passing these from YAP manually. Using PHP, a quick way of passing them through is by turning the POST array into a query string. To help get you started, the following is an example using PHP 5. However, please note, because this effectively prints your variables to the page, it is not a very secure method. This is only meant to get you started.

Note, this tag is not available in the small box view.

YAP will also handle OAuth for you by sending the access token and secret in the POST request to your app. You can use these directly instead of making a separate request to our OAuth servers.

Authentication & Security in Flash

Building an application with security in mind is always a good development practice.

When using OAuth, you are provided a consumer key and secret, and can make a request for an access token and secret. You should avoid printing these keys anywhere on your page (don't pass them through flashvars) or hardcoding them into the SWF application. Doing so could expose the keys to 'evil doers'. However, due to the nature of client applications, this typically means that the consumer secret must be distributed with the application, which inheritably compromises them.

While the implementation is left up to you; a good solution is to store the consumer secret only on the server-side, and store the access tokens on the server paired against the GUID (the user) it represents. Then, when your application loads, make a request to your server using the viewer GUID and a temporary session ID that only allows access to that resource for a short period of time. If valid, return the consumer secret and access token / secret to begin your session.

You may find the PHP SDK very useful for making server-side OAuth requests.

Examples

Now that you've got a grasp on how the API works and what's involved, it's time to see it in action. The best way to learn is by looking at some sample code. To help you get started, we've included code snippets to show you how to accomplish a specific task, as well as full demo applications in both Flash and Flex.

Terms of Use

Use of the Yahoo! Social APIs is governed by the Yahoo! APIs Terms of Use.

Copyright © 2009 Yahoo! Inc. All rights reserved. Copyright | Privacy Policy

Help us continue to improve the Yahoo! Developer Network: Send Your Suggestions