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
Balu_SFDCBalu_SFDC 

FaceBook Comments on the posts

hi.....

i integrated with Facebook...now i want to give the comment to the post from my VF Page...

how can we achive this......

 here is the some code

VF Page

<apex:page controller="FacebookSampleController" action="{!login}"
cache="false" sidebar="false" showHeader="false"
title="Force.com Toolkit for Facebook - Sample Page">
<apex:stylesheet value="{!URLFOR($Resource.style)}"/>
<script src="{!$Resource.jquery}"></script>
<script src="{!$Resource.html_sanitizer}"></script>
<script>
var $j = jQuery.noConflict();

function getFriends() {
// Show the throbber
$j("#friends").html('<img src="{!$Resource.ajax}" width="16" height="11"/>');

// The remote method can't get the access token via the cookie, so we
// get it from an action method and pass it here
FacebookSampleController.getFriends('{!accessToken}', function(result, event) {
if (event.status) {
// result comes back escaped - use Caja to unescape it
var json = html.unescapeEntities(result);
var friends = JSON.parse(json);
// Truncate the array to a maximum of 10 friends
friends.data.length = Math.min(10, friends.data.length);
$j("#friends").html('<pre>'+JSON.stringify(friends, null, ' ')+'</pre>');
} else {
alert(event.message + '\n' + JSON.stringify(event));
}
});
}

function showUserDataThrobber() {
$j("#user").html('<img src="{!$Resource.ajax}" width="16" height="11"/>');
}
</script>
<h1>Force.com Toolkit for Facebook</h1>
<br/>
<br/>
<h2>Sample Page</h2>&nbsp;&nbsp;<apex:outputLink value="FacebookTestUser">Test User Connections</apex:outputLink>
<p>This page shows you how to use the Force.com Toolkit for Facebook.</p>

<h2>{!me.name}</h2>
<br/>
<c:FacebookProfilePicture fbid="{!me.id}" width="120" height="120" type="large"/>
<br/>
<br/>

<h2>Status</h2>
<apex:form >
<apex:inputText value="{!message}" id="message"/>&nbsp;&nbsp;
<apex:commandButton value="Post" action="{!postToFeed}" rerender="posts"/>
</apex:form>
<br/>

<apex:form >
<h2>Your Feed</h2>&nbsp;&nbsp;<apex:commandButton value="Refresh" rerender="posts"/>
<apex:outputPanel id="posts">
<br/><apex:outputText value="{!error}" />
<apex:dataTable value="{!myPosts.data}" var="post" cellpadding="5">
<apex:column style="vertical-align:top;">
<c:FacebookProfilePicture fbid="{!post.from_z.id}" width="60" height="60" />
</apex:column>
<apex:column >
<b>{!post.from_z.name}</b><br/>
{!post.message}<br/>
{!post.story}<br/>
{!post.created_time}<br/>
{!post.likes.count}{!IF(ISBLANK(post.likes), "", IF((post.likes.count == 1), " Like ", " Likes "))}
<apex:commandLink value="Delete" action="{!deletePost}" rerender="posts">
<apex:param name="postId" value="{!post.id}" assignTo="{!postId}"/>
</apex:commandLink>
<br/>
<apex:inputText value="{!message1}" id="message"/>&nbsp;&nbsp;
&nbsp;&nbsp;
<apex:commandbutton value="reply" action="{!postToReply}" rerender="posts">
<apex:param name="ReplyId" value="{!post.id}" assignTo="{!replyId}"/>
</apex:commandbutton>

<apex:dataTable value="{!post.comments.data}" var="comment" cellpadding="5">
<apex:column style="vertical-align:top;">
<c:FacebookProfilePicture fbid="{!comment.from_z.id}" width="40" height="40" type="small"/>
</apex:column>
<apex:column >
<b>{!comment.from_z.name}</b><br/>
{!comment.message}<br/>
{!comment.created_time}<br/>
{!comment.likes}{!IF(ISBLANK(comment.likes), "", IF((comment.likes == 1), " Like", " Likes"))}
<apex:commandLink value="Reply" action="{!postToReply}" reRender="posts" >
<apex:param name="replyId" value="{!comment.id}" assignTo="{!replyId}"/>
</apex:commandLink>&nbsp;&nbsp;
<apex:commandLink value="delete" action="{!deletecmt}" reRender="posts">
<apex:param name="cmtId" value="{!comment.id}" assignTo="{!cmtId}"/>
</apex:commandlink>
</apex:column>
</apex:dataTable>
</apex:column>
</apex:dataTable>
</apex:outputPanel>
</apex:form>
<hr/>

<h2>Your user record in JSON (via action method):</h2>
<apex:form >
<apex:commandButton value="Get It Now!" onclick="showUserDataThrobber();" action="{!getUserData}" rerender="userPanel"/>
</apex:form>
<apex:outputPanel id="userPanel">
<script>
// Use a little JavaScript to pretty print the JSON
var user = {!facebookUser};
$j("#user").html('<pre>'+JSON.stringify(user, null, ' ')+'</pre>');
</script>
<pre id="user"></pre>
</apex:outputPanel>
<hr/>

<h2>10 of your friends in JSON (via JS remoting):</h2>
<br/>
<input type="submit" class="btn" onclick="getFriends();" value="Get Them Now!"/>
<pre id="friends"></pre>

<hr/>
(Note: the following tags are intended to be used on a sites page in order to get the correct share url. To view them correctly, expose this page as a sites page)
<p>Facebook like tag:</p>
<c:FacebookLike />

<p>Facebook recommendations tag:</p>
<c:FacebookRecommendations />

<p>Facebook Activities tag:</p>
<c:FacebookActivity />
</apex:page>

-----------------------

Apex Class

-------------------

/**
* @author Pat Patterson - ppatterson@salesforce.com
*/

global with sharing class FacebookSampleController extends FacebookLoginController {
// Set this to an auth provider id (e.g. '0SOD00000000012') to use an
// auth provider (new in Spring '12)
private static String authProviderId = null;

public String message {get; set;}
public String message1 {get; set;}
public String postId {get; set;}
public string cmtId{get;set;}
public String userData {get; set;}
public String error {get; set;}
public String messageId{get;set;}
public string replyId{get;set;}
public FacebookSampleController() {
userData = 'null';
}

// You wouldn't usually need to override login(). We do here to be able
// to change the behavior depending on whether we want to use the platform
// auth provider. If you want to use the auth provider in your controller,
// just don't extend FacebookLoginController
public override PageReference login() {
return ( authProviderId == null ) ? super.login() : null;
}

public static String getAccessToken() {
return ( authProviderId == null )
? FacebookToken.getAccessToken()
: Auth.AuthToken.getAccessToken(authProviderId, 'facebook');
}

public FacebookUser me {
get {
try {
// Can't set up 'me' in the controller constructor, since the superclass
// 'login' method won't have been called!
if (me == null) {
String accessToken = getAccessToken();

// If accessToken is null, it's likely that the page's action
// method has not yet been called, so we haven't been to FB to
// get an access token yet. If this is the case, we can just
// leave 'me' as null, since the redirect will happen before
// HTML is send back.
if (accessToken != null) {
me = new FacebookUser(accessToken, 'me');
}
}
} catch (Exception e) {
error = e.getMessage();
}

return me;
} set;
}

public FacebookPosts myPosts {
get {
try {
String accessToken = getAccessToken();

if (accessToken != null) {
myPosts = new FacebookPosts(accessToken, 'me/feed', null);
}
} catch (Exception e) {
error = e.getMessage();
}

return myPosts;
} set;
}

// Returns JSON string with user info
public String getFacebookUser() {
return userData;
}

public PageReference getUserData() {
error = null;

try {
userData = FacebookUtil.get(getAccessToken(), 'me');
} catch (Exception e) {
error = e.getMessage();
}

return null;
}

// Can't get the cookies in a remote method, so pass it in explicitly
@RemoteAction
global static String getFriends(String accessToken) {
String friends = null;

try {
friends = FacebookUtil.get(accessToken, 'me/friends');
} catch (Exception e) {
// Can't set the error message in a static method, so let's
// just return it
friends = e.getMessage();
}

return friends;
}

public PageReference postToFeed() {
error = null;

try {
if (message != null) {
FacebookPublish.postToWall(getAccessToken(), 'me', new Map<String, String>{'message' => message});
}

message = null;
} catch (Exception e) {
error = e.getMessage();
}

return null;
}
public PageReference postToReply() {
error = null;

try {

if(message1 != null)
{

FacebookPublish.postcomment(getAccessToken(),this.replyId,new Map<String, String>{'message' => message1});

}

message1 = null;

} catch (Exception e) {
error = e.getMessage();
}

return null;

}
public PageReference deletePost() {
error = null;

try {
if (postId != null) {
FacebookUtil.deleteItem(getAccessToken(), postId);
}

postId = null;
} catch (Exception e) {
error = e.getMessage();
}

return null;
}

public PageReference deletecmt() {
error = null;

try {
if (cmtId != null) {
FacebookUtil.deleteItem(getAccessToken(), cmtId);
}

cmtId = null;
} catch (Exception e) {
error = e.getMessage();
}

return null;
}

static testMethod void testController() {
// TODO
}
}

 

plz give the reply......

thanks in advance..........

 

Regards........

Balu