OAuth
The following example is designed for using together with Zend Framework (see http://framework.zend.com/ for details about ZF).
The next one is a simple example of non web-based application, which uses our test library (it is strongly not recommended to use this library in production enviroment, only as a sample, use time-tested libraries for different programming languages).
An example of authenticating app using oAuth headers
Token based (OAuth is recommended)
The libraries can be found in the libraries section of the site.
Code Examples
The following code examples that use the oDesk APIs.
Examples that use the oDesk API PHP library
The following PHP examples are designed for version 0.3 of the oDesk PHP API library (updated on 7/27/2010)
- A bare bones example that retrieves a screen snap from the team room.
- A more complex example that retrieves the most recent screen snap and then updates the memo associated with it.
- An example of using the API library in a non-web environment.
- An example of posting job in a non-web enviroment
Examples of using the oDesk Ruby library
$:.unshift 'lib'
require 'json'
require 'API_Post'
require 'API_rexml'
require 'oDeskAPI.lib'
API_SECRET = 'api key secret here'
API_KEY = '<api key here>'
API_TEAM_URL = 'https://www.odesk.com:/api/team/v1/teamrooms/mytestcompany.json'
# start auth and get auth url
api = ODeskAPI.new API_SECRET, API_KEY
url = api.auth
# open auth url in browser
@browser.goto(url) # where @browser an instance of your system's browser
@browser.button(:id, "authorize").click
@browser,close()
# get auth token
token= api.get_api_token
# send GET request
data = api.get_request(API_TEAM_URL, {'online' => 'all'})
json = JSON.parse(data)
p 'auth as: ' + json['auth_user']['uid']
p 'full response: ' + json.to_s
Check sample Ruby library to run the example above.
Examples of using the oDesk Java library
import java.util.HashMap;
import org.json.JSONException;
import org.json.JSONObject;
import com.oDesk.api.*;
public class MyTestApp {
final String requestUrl = "https://www.odesk.com:/api/team/v1/teamroom/mytestcompany.json";
String url;
String apiToken;
onCreate() {
String secret = "<your secret here>";
String api_key = "<your api key here>";
oDeskAPI api = new oDeskAPI(secret, api_key);
try {
// get auth url to open in system's browser
url = api.getAuthUrl();
} catch (JSONException e) {
e.printStackTrace();
}
// {{{ open your system browser and authorize application, e.g. for Android
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
intent.addCategory("android.intent.category.BROWSABLE");
intent.setData(Uri.parse(url));
startActivity(intent);
// }}}
// wait until browser finishes authorization
// get token
try {
apiToken = api.getApiToken();
} catch (JSONException e) {
e.printStackTrace();
}
// send request
try {
HashMap<String, String> p = new HashMap<String, String>();
p.put("online", "all");
JSONObject json = api.getRequest(requestUrl, p);
JSONObject data = json.getJSONObject("auth_user");
uid = data.getString("uid");
System.out.println("auth as " + uid);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
Authentication & Email Example
oDesk Message Center notification that contains a detailed Authentication example.
View and download the code here.
Cross Domain Requests in AJAX
See our short JQuery cross-domain example
Examples of Applications that use the oDesk API
Below are examples of applications of applications that use the oDesk API.
Simple RoR library example
http://simple-desk.heroku.com/ (* non-official oDesk's application)
This is a good example of how an application should ask for permissions. This particular example uses the Ruby on Rails library. The links to the sources can be found here.
Provider Profile Promoter
The oDesk Provider Promotion widget (http://www.odesk.com/d/promote.php) uses the pubic API to query information from a provider profile and render it in a javascript embeddable widget.
Inspiration
The sky is the limit.
Here are a few ideas for applications that could leverage the oDesk APIs. Please send us your ideas.
Mobile Apps:
- iPhone Apps
- Android Apps
- Palm Apps
Web Apps:
- Job aggregators
- Contractor and Employee browsers
- Contractor and Employee tools
Desktop Apps:
- Inegration with project management software
- Integration with acconting software
- Integration with time and task tracking software
Comments (0)
You don't have permission to comment on this page.