Social Apps with the Force.com Toolkit for Facebook

25
Social Apps with the Force.com Toolkit for Facebook Pat Patterson, salesforce.com, Principal Developer Evangelist @metadaddy

Transcript of Social Apps with the Force.com Toolkit for Facebook

Page 1: Social Apps with the Force.com Toolkit for Facebook

Social Apps with the Force.com

Toolkit for Facebook

Pat Patterson, salesforce.com, Principal Developer Evangelist

@metadaddy

Page 2: Social Apps with the Force.com Toolkit for Facebook

Safe Harbor

Safe harbor statement under the Private Securities Litigation Reform Act of 1995:

This presentation may contain forward-looking statements that involve risks, uncertainties, and assumptions. If any such uncertainties materialize or if

any of the assumptions proves incorrect, the results of salesforce.com, inc. could differ materially from the results expressed or implied by the forward-

looking statements we make. All statements other than statements of historical fact could be deemed forward-looking, including any projections of

product or service availability, subscriber growth, earnings, revenues, or other financial items and any statements regarding strategies or plans of

management for future operations, statements of belief, any statements concerning new, planned, or upgraded services or technology developments

and customer contracts or use of our services.

The risks and uncertainties referred to above include – but are not limited to – risks associated with developing and delivering new functionality for our

service, new products and services, our new business model, our past operating losses, possible fluctuations in our operating results and rate of growth,

interruptions or delays in our Web hosting, breach of our security measures, the outcome of intellectual property and other l itigation, risks associated

with possible mergers and acquisitions, the immature market in which we operate, our relatively limited operating history, our ability to expand, retain,

and motivate our employees and manage our growth, new releases of our service and successful customer deployment, our limited history reselling

non-salesforce.com products, and utilization and selling to larger enterprise customers. Further information on potential factors that could affect the

financial results of salesforce.com, inc. is included in our annual report on Form 10-Q for the most recent fiscal quarter ended July 31, 2012. This

documents and others containing important disclosures are available on the SEC Filings section of the Investor Information section of our Web site.

Any unreleased services or features referenced in this or other presentations, press releases or public statements are not currently available and may

not be delivered on time or at all. Customers who purchase our services should make the purchase decisions based upon features that are currently

available. Salesforce.com, inc. assumes no obligation and does not intend to update these forward-looking statements.

Page 3: Social Apps with the Force.com Toolkit for Facebook

Pat Patterson

Principal Developer Evangelist

@metadaddy

Page 4: Social Apps with the Force.com Toolkit for Facebook

Objectives

Understand the Facebook Graph API

Be able to use the Force.com Toolkit for Facebook in an app

Understand how users can use their Facebook identity to login

to Salesforce

Page 5: Social Apps with the Force.com Toolkit for Facebook

Agenda

The Facebook Graph API

The Force.com Toolkit for Facebook

Social Sign-On with Authentication Providers

Create a social application on Force.com

Login from Facebook

Share with friends

Post to timeline

Page 6: Social Apps with the Force.com Toolkit for Facebook

The Facebook Graph API

https://developers.facebook.com/docs/reference/api/

Page 7: Social Apps with the Force.com Toolkit for Facebook

Accessing Social Graph Objects

Every social graph object has a unique ID

https://graph.facebook.com/ID

For example, ‘Facebook Platform’ has ID 19292868552

GET https://graph.facebook.com/19292868552

Page 8: Social Apps with the Force.com Toolkit for Facebook

Relationships – Edges on the Graph

Friends, feed (wall/timeline), likes, photos, videos, etc

Graph API terminology: connections

https://graph.facebook.com/ID/CONNECTION_TYPE

For example, my friends

Special ID - me

GET https://graph.facebook.com/me/friends

Page 9: Social Apps with the Force.com Toolkit for Facebook

Graph API Authorization

OAuth 2.0

Redirect to Facebook; user authenticates (if necessary) and gives

permission for app to access the Graph API

App receives access token representing the user’s permission to

access their social graph

App sends access token with Graph API calls as a query parameter

https://graph.facebook.com/ID?access_token=TOKENVALUE

Page 10: Social Apps with the Force.com Toolkit for Facebook

Graph API Permissions

Access to specific types of graph objects is controlled by

permissions

user_likes, friends_photos, publish_stream etc

Requested via scope parameter in OAuth 2.0 request

Balance app functionality against intrusiveness

Page 11: Social Apps with the Force.com Toolkit for Facebook

Searching

GET https://graph.facebook.com/search?q=force.com&type=post

Page 12: Social Apps with the Force.com Toolkit for Facebook

Publishing

HTTP POST to a connection URL

Access token is required!

curl -F 'access_token=...' \

-F 'message=Hello world!' \

https://graph.facebook.com/me/feed

Response: {"id":"667905711_10151088147280712"}

Page 13: Social Apps with the Force.com Toolkit for Facebook

Graph API Explorer

https://developers.facebook.com/tools/explorer

Page 14: Social Apps with the Force.com Toolkit for Facebook

Force.com Toolkit for Facebook

http://wiki.developerforce.com/page/Facebook_Toolkit

Apex binding for the Facebook Graph API

Map<String,String> params =

new Map<string,string>{'fields' => 'id,name',

'limit' => '10'};

FacebookUsers friends =

new FacebookUsers(access_token, 'me/friends', params);

for (FacebookUser friend : friends.data) {

System.debug(friend.name);

}

Page 15: Social Apps with the Force.com Toolkit for Facebook

Force.com Toolkit for Facebook

Graph API objects modeled as Apex classes

FacebookUser, FacebookPhoto etc

<apex:page controller=“FriendsController”>

<apex:pageSectionTable value=“{!friends}” var=“friend”>

<apex:column value=“{!friend.name}”>

</apex:pageSectionTable>

</apex:page>

Open source, but unsupported

Page 16: Social Apps with the Force.com Toolkit for Facebook

Social Sign-On from Facebook to

Customer Portal

Authentication Provider

Built into Force.com Platform

Performs ‘app’ side of OAuth flow

Maps Facebook user to Customer Portal user via Registration Handler

class

Can also map to org users, but not as useful in the Facebook context!

Page 17: Social Apps with the Force.com Toolkit for Facebook

Leveraging the Social Graph

How do we get our customer portal to ‘go viral’?

Allow users to invite their friends

Super-easy from JavaScript in a Visualforce page with Facebook Dialogs

FB.ui({

method: 'send',

to: '123456789',

name: 'Check out this great site!',

description: 'My Portal has everything you need.’,

link: 'http://myportalurl.force.com/',

});

Page 18: Social Apps with the Force.com Toolkit for Facebook

Building a Social App

Want to (optionally) publish a link to the user’s wall when they

close a case – encourage more friends to come use the portal!

Can we show a checkbox to allow the user to publish to their

wall at the time they close the case, with no Facebook dialog?

Page 19: Social Apps with the Force.com Toolkit for Facebook

Getting an Access Token – Customer Portal

public class MyPageController {

private static String authProviderId = // Get custom setting;

public String getAccessToken(){

Auth.AuthToken.getAccessToken(authProviderId, 'facebook');

}

...

}

<apex:page controller=”MyPageController”

cache="false" sidebar="false" showHeader="false” title=”My Page”>

Page 20: Social Apps with the Force.com Toolkit for Facebook

One Shortcoming with Authentication Provider

scope is fixed to email

email address + ‘basic info’ (friends list etc)

Right now, out of the box, Authentication Providers work great

for Social Sign-On, but don’t allow very rich social apps

Unless…

Page 21: Social Apps with the Force.com Toolkit for Facebook

Widening Scope

Workaround for fixed scope

Use Facebook JavaScript SDK to request additional permissions

// We need some permissions - ask for them

FB.login(function(response) {

if (!response) {

alert('Error getting permission!');

} else {

location.reload(true);

}

}, {scope: reqperms});

Page 22: Social Apps with the Force.com Toolkit for Facebook

Wrapping Up

The Facebook JavaScript SDK and Dialogs allow simple social

actions from Visualforce

The Force.com Toolkit for Facebook gives access to the Graph

API from Apex

Authentication Providers allow Social Sign-On to customer

portals

Page 23: Social Apps with the Force.com Toolkit for Facebook

Go out and build something cool!

Page 24: Social Apps with the Force.com Toolkit for Facebook

Pat Patterson

Principal Developer Evangelist,

@metadaddy

Page 25: Social Apps with the Force.com Toolkit for Facebook