function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
RupBRupB 

Facebook toolkit - sample needs update, can't get to FacebookSession instance

Hi,

 

In the Facebook toolkit, this sample

 

public class FBToolkitPageController {

public FacebookApp__c fbc { get; set; }

public FacebookConnection fbConnection { get; set; }

public List<String> friendsList { get { return FacebookConnection.friendsList; } set; }

public FBToolkitPageController() {

if (FacebookConnection.fbApp != null) {

System.debug(LoggingLevel.INFO, FacebookConnection.fbApp.AppKey__c);

System.debug(LoggingLevel.INFO, FacebookConnection.fbApp.AppSecret__c);

System.debug(LoggingLevel.INFO, FacebookConnection.fbApp.FBUserId__c);

fbc = FacebookConnection.fbApp;

}

}

 

 is out of date.  Could someone tell me how I can get hold of the current FacebookSession object, once I have connected to Facebook with FacebookConnect ?   On the JavaScript/VisualForce side of things, I can reach it like this :

 

var api = FB.Facebook.apiClient;

var session = api.get_session();

 

 But how do I get hold of this in my controller on the Apex side ?

 

Thanks for your help,

Rup 

 

 

Message Edited by RupB on 15-10-2009 12:28 AM
Best Answer chosen by Admin (Salesforce Developers) 
RupBRupB

Here is an answer to my own question :

 

Controller, APEX class : 

 

 

public with sharing class My_Controller extends AbsSocialController { public FBCAuthenticator myauth; public String facebookUserId { get; set; } public String facebookAPIKey { get; set; } public override void setAuthenticator(AbsAuthenticator auth) { monDebug += '> setAuthenticator APPELé'; super.setAuthenticator(auth); myauth = (FBCAuthenticator)auth; if (myauth != null) { facebookUserId = myauth.uid; facebookAPIKey = myauth.APIKey; } return; } // get my Facebook friends public FacebookUserInfo[] getMyFriends() { FacebookSession sess = new FacebookSession(myauth); List<String> params = new List<String>(); params.add('about_me'); params.add('pic'); params.add('activities'); params.add('first_name'); params.add('last_name'); params.add('name'); params.add('is_app_user'); params.add('locale'); params.add('hometown_location'); params.add('status'); return sess.getUserInfo(sess.getFriends(), params); } }

 

 Display, VisualForce page :

 

<apex:page controller="My_Controller" showHeader="true" > <h1>{!$User.Email}, {!$Site.Name}, {!$User.Id} </h1> <apex:form > <c:FacebookConnect myController="{!pageController}" autoCheckConnection="yes" loginMessage="You can now use Facebook to login to this site!" loginFooterMessage="You can use this area to provide some fine print for you use if you so choose." /> <hr /> <apex:outputText value="Mes essais : " style="font-size: 12pt" /> <apex:outputText value=" Current User's Facebook Id: " /> <apex:outputText value="{!facebookUserId}" /> <apex:outputText value=" Facebook API key: " /> <apex:outputText value="{!facebookAPIKey}" /> <br /> <apex:pageBlock > <apex:pageBlockSection title="FACEBOOK : my Friends "> <apex:dataTable value="{!MyFriends}" var="f" styleClass="list"> <apex:column > <apex:facet name="header">Name</apex:facet> <apex:outputText value="{!f.name}"/> </apex:column> <apex:column > <apex:facet name="header">Uses our App ?</apex:facet> <apex:outputText value="{!f.is_app_user}"/> </apex:column> <apex:column > <apex:facet name="header">Locale</apex:facet> <apex:outputText value="{!f.locale}"/> </apex:column> <apex:column > <apex:facet name="header">Activities</apex:facet> <apex:outputText value="{!f.activities}"/> </apex:column> <apex:column > <apex:facet name="header">City</apex:facet> <apex:outputText value="{!f.hometown_location.city}"/> </apex:column> <apex:column > <apex:facet name="header">Status</apex:facet> <apex:outputText value="{!f.status.message}"/> </apex:column> </apex:dataTable> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>

 

 I hope that helps !

Rup

 

 

All Answers

RupBRupB

Here is an answer to my own question :

 

Controller, APEX class : 

 

 

public with sharing class My_Controller extends AbsSocialController { public FBCAuthenticator myauth; public String facebookUserId { get; set; } public String facebookAPIKey { get; set; } public override void setAuthenticator(AbsAuthenticator auth) { monDebug += '> setAuthenticator APPELé'; super.setAuthenticator(auth); myauth = (FBCAuthenticator)auth; if (myauth != null) { facebookUserId = myauth.uid; facebookAPIKey = myauth.APIKey; } return; } // get my Facebook friends public FacebookUserInfo[] getMyFriends() { FacebookSession sess = new FacebookSession(myauth); List<String> params = new List<String>(); params.add('about_me'); params.add('pic'); params.add('activities'); params.add('first_name'); params.add('last_name'); params.add('name'); params.add('is_app_user'); params.add('locale'); params.add('hometown_location'); params.add('status'); return sess.getUserInfo(sess.getFriends(), params); } }

 

 Display, VisualForce page :

 

<apex:page controller="My_Controller" showHeader="true" > <h1>{!$User.Email}, {!$Site.Name}, {!$User.Id} </h1> <apex:form > <c:FacebookConnect myController="{!pageController}" autoCheckConnection="yes" loginMessage="You can now use Facebook to login to this site!" loginFooterMessage="You can use this area to provide some fine print for you use if you so choose." /> <hr /> <apex:outputText value="Mes essais : " style="font-size: 12pt" /> <apex:outputText value=" Current User's Facebook Id: " /> <apex:outputText value="{!facebookUserId}" /> <apex:outputText value=" Facebook API key: " /> <apex:outputText value="{!facebookAPIKey}" /> <br /> <apex:pageBlock > <apex:pageBlockSection title="FACEBOOK : my Friends "> <apex:dataTable value="{!MyFriends}" var="f" styleClass="list"> <apex:column > <apex:facet name="header">Name</apex:facet> <apex:outputText value="{!f.name}"/> </apex:column> <apex:column > <apex:facet name="header">Uses our App ?</apex:facet> <apex:outputText value="{!f.is_app_user}"/> </apex:column> <apex:column > <apex:facet name="header">Locale</apex:facet> <apex:outputText value="{!f.locale}"/> </apex:column> <apex:column > <apex:facet name="header">Activities</apex:facet> <apex:outputText value="{!f.activities}"/> </apex:column> <apex:column > <apex:facet name="header">City</apex:facet> <apex:outputText value="{!f.hometown_location.city}"/> </apex:column> <apex:column > <apex:facet name="header">Status</apex:facet> <apex:outputText value="{!f.status.message}"/> </apex:column> </apex:dataTable> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>

 

 I hope that helps !

Rup

 

 

This was selected as the best answer
Light DintLight Dint

Hi, RupB :

how can i fix this bug.

 

FacebookSession.FacebookClientException: 102: parameters uid or session key required

 

Class.FacebookSession.checkResponse: line 219, column 16 Class.FacebookSession.getFriends: line 164, column 9 Class.My_Controller.getMyFriends: line 39, column 33 External entry point