Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Make your likes visible on Facebook?

Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.

No, thanks

Tour de API

No description
by

Anne-Sofie Nielsen

on 15 January 2013

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of Tour de API

Facebook What is OAuth ?
Why do I need to know? See OAuth.net
Java
.NET
Ruby
Python
JavaScript
... Libraries Twitter 1) Create Application @ Twitter
2a) Use to create a desktop application
2b) Use to create a web application LinkedIn App permissions determined by scope parameter @ the Warm Crocodile Conference Tour de API Anne-Sofie Nielsen OAuth http://oauth.net/
http://hueniverse.com/oauth/
http://dev.twitter.com
http://developer.linkedin.com
http://developers.facebook.com Resources @femalenerd OAuth 1.0 OAuth 2.0 Client Consumer Service Provider (a user of your application) (your application) (e.g. Twitter) "Click here..." Consumer key, consumer secret, callback URL Request token (temporary) HTTP Redirect +
request token HTTP GET that page Here's the page Click "Authorize" Redirect to the callbackURL
+ verifier HTTP GET that page Verifier Access token
(token + secret) Controversial "standard"

Beware: Tokens may need to be refreshed Click here and I'll tell you what people think about OAuth @migueldeicaza
“OAuth2. The SOAP of Authentication" http://programmingisterrible.com/ Examples in this presentation are in Java,
based on Scribe by @fernandezpablo

https://github.com/fernandezpablo85/scribe-java package org.scribe.examples;

import org.scribe.builder.*;
import org.scribe.builder.api.*;
import org.scribe.model.*;
import org.scribe.oauth.*;
import java.util.*;

public class MyFirstTwitterApp {

public static void main(String[] args) {
OAuthService service = new ServiceBuilder() .provider(TwitterApi.class) .apiKey("w5YVcwT0c3qNRAhNMypnDQ") .apiSecret("fSbTS0AIGuXb7J3nNvRfkp1pfCFWVBJRCoepVX0aY")
.build();
Scanner in = new Scanner(System.in);

Token requestToken = service.getRequestToken();
System.out.println("Now go and authorize the application here:");
System.out.println(service.getAuthorizationUrl(requestToken));
System.out.println("And paste the verifier here");
System.out.print(">>");
Verifier verifier = new Verifier(in.nextLine());
System.out.println();

Token accessToken = service.getAccessToken(requestToken, verifier);

OAuthRequest request = new OAuthRequest(Verb.GET, "https://api.twitter.com/1.1/search/tweets.json?q=OAuth");
service.signRequest(accessToken, request);
Response response = request.send();
System.out.println(response.getBody());
}

} Twitter desktop app: <%@ page import="org.scribe.oauth.*" %>
<%@ page import="org.scribe.builder.*" %>
<%@ page import="org.scribe.builder.api.*" %>
<%@ page import="java.util.*" %>
<%@ page import="org.scribe.model.*" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
OAuthService service = new
ServiceBuilder().provider(TwitterApi.class)
.apiKey("w5YVcwT0c3qNRAhNMypnDQ")
.apiSecret("fSbTS0AIGuXb7J3nNvRfkp1pfCFWVBJRCoepVX0aY")
.callback("http://10.10.40.163:8080/callback.jsp")
.build();

Token requestToken = service.getRequestToken();

request.getSession().setAttribute("requestToken", requestToken);

response.sendRedirect(
service.getAuthorizationUrl(requestToken));
%> First page: authorize.jsp <%@ page import="org.scribe.builder.*" %>
<%@ page import="org.scribe.builder.api.*" %>
<%@ page import="org.scribe.model.*" %>
<%@ page import="org.scribe.oauth.*" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html><head><title></title></head><body>

<% OAuthService service = new ServiceBuilder()
.provider(TwitterApi.class)
.apiKey("w5YVcwT0c3qNRAhNMypnDQ")
.apiSecret("fSbTS0AIGuXb7J3nNvRfkp1pfCFWVBJRCoepVX0aY")
.callback("http://10.10.40.163:8080/callback.jsp")
.build();
Token requestToken = (Token) request.getSession().getAttribute("requestToken");
Token accessToken = service.getAccessToken(requestToken,
new Verifier(request.getParameter("oauth_verifier")));

OAuthRequest oAuthRequest = new OAuthRequest(Verb.GET,
"https://api.twitter.com/1.1/search/tweets.json?q=OAuth");
service.signRequest(accessToken, oAuthRequest);
Response twitterResponse = oAuthRequest.send();
%>

<%= twitterResponse.getBody() %>

</body></html> Second page: callback.jsp (...)
Response twitterResponse = oAuthRequest.send();

String resultAsString = twitterResponse.getBody();
JSONObject resultAsJSON = new JSONObject(resultAsString);
JSONArray statuses = resultAsJSON.getJSONArray("statuses");

for (int i = 0; i < statuses.length(); i++) {
JSONObject status = statuses.getJSONObject(i);
JSONObject userFromStatus = status.getJSONObject("user");
%>
<p>@<%= userFromStatus.getString("screen_name")%>:
<%= status.getString("text") %></p>
<% }
%> Add some JSON parsing & selection http://www.json.org/java/ callback.jsp should store the access token in the session Maturing the application
request.getSession().setAttribute("accessToken", accessToken); and redirect to a page that uses the access token to do the actual Twitter search Access tokens should be persisted so the user will not have to re-authorize when using your application again tomorrow request.sendRedirect("twitterSearch.jsp") Search for tweets
Filter based on geographical location or (detected) language
Post tweets
Get information about friends and followers
Retrieve and update lists of users
Send or retrieve direct messages Useful things to do with the
Twitter REST API ... and the less useful things Update profile color scheme ... and beware of the rate limits! OAuthService service =
new ServiceBuilder()
.provider(LinkedInApi.class)
.apiKey("jbd8sv2azisq")
.apiSecret("9PtwB75hMoZJDhkk")
.scope("r_basicprofile r_emailaddress")
.build(); Posts only to the developers of the app when in "development mode" Thanks! <%@ page import="org.scribe.oauth.*" %>
<%@ page import="org.scribe.builder.*" %>
<%@ page import="org.scribe.builder.api.*" %>
<%@ page import="java.util.*" %>
<%@ page import="org.scribe.model.*" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
OAuthService service = new ServiceBuilder()
.provider(FacebookApi.class)
.apiKey("405052276235832")
.apiSecret("df7052786a75d93c7673d191ca775ef5")
.callback("http://localhost:8080/callback.jsp")
.build();

response.sendRedirect(service.getAuthorizationUrl(null));
%> First page: authorize.jsp No request token! (...)
<%
OAuthService service = new ServiceBuilder()
.provider(FacebookApi.class)
.apiKey("405052276235832")
.apiSecret("df7052786a75d93c7673d191ca775ef5")
.callback("http://localhost:8080/callback.jsp")
.build();

Token accessToken = service.getAccessToken(null,
new Verifier(request.getParameter("code")));
OAuthRequest oAuthRequest = new OAuthRequest(Verb.GET,
"https://graph.facebook.com/me");
service.signRequest(accessToken, oAuthRequest);
Response response = oAuthRequest.send();
%>

<%= response.getBody() %> Second page: callback.jsp http://api.linkedin.com/v1/people-search
:(people:(first-name,last-name,headline,public-profile-url))?
keywords=oauth&country-code:dk&format=json&count=3 LinkedIn People Search Example REST call OAuthRequest oAuthRequest = new OAuthRequest(Verb.GET,
"http://api.linkedin.com/v1/people/~:(first-name,email-address)");
service.signRequest(accessToken, oAuthRequest);
Response response = oAuthRequest.send(); Response: <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<person>
<first-name>Anne-Sofie</first-name>
<email-address>fie@fie.dk</email-address>
</person> Task: Find top 3 OAuth experts in your network Scope: r_network
Full transcript