STEP 1 : Login To (https://developers.facebook.com/)
STEP 2 : Give your face book credentials and login
STEP 3 : Go to APP Tab (add new app)
STEP 4 : Select website and give APP Name (Click on create new Facebook App id)
STEP 4 : Under Category Section select (Apps for pages) and click (Create app id)
STEP 5 : Under (Tell us about your website) Section Site Url = Give your Visual force page url
(https://c.ap1.visual.force.com/apex/facebookPage) and click (Next)
Note: Before going to this process create a visual force page with page name (facebookPage) and controller (FaceBookController)
VF:
<apex:page controller="FaceBookController">
<apex:form >
<apex:commandButton value="ClickMe" action="{!fbAction}"/>
</apex:form>
</apex:page>
Controller:
public with sharing class FaceBookController {public PageReference fbAction() {HttpRequest req=new HttpRequest();req.setMethod('GET');req.setEndpoint('https://graph.facebook.com/oauth/access_token? client_id=0000000000000000&redirect_uri=https://c.ap1.visual.force.com/apex/facebookPage&client_secret=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx&code=oxoxoxoxoxoxoxoxoxoxoxoxoxo');HttpResponse res = new HttpResponse();http h = new Http();res = h.send(req);system.debug( 'Aceestoken-------'+res.getbody());return null;}}
STEP 6 : Click on Finish
STEP 7 : Copy the (App Id) and (App Secret)
STEP 8 : Authenticate URL
https://www.facebook.com/dialog/oauth?client_id=1505806869677932&redirect_uri=https://c.ap1.visual.force.com/apex/fbpage&scope=user_about_me,read_mailbox,read_insights,user_photos,friends_photos,publish_stream,read_friendlists,read_insights,read_requests,read_stream,xmpp_login,ads_management,create_event,manage_friendlists,manage_notifications,&state=immu1038
In the above url replace
1. client_id : with your Facebook App Id (EX: 1573492886214474)
2. redirect_uri : With your VF page url (EX: https://c.ap1.visual.force.com/apex/facebookPage )
3. state : Any string (EX: abcsdefg..)
Copy the above Authenticate URl
Open a new tab in browser paste it and click enter
It will redirect to visual force page
STEP 9 : Copy the redirect page URL and Paste in note pad
EX:
https://c.ap1.visual.force.com/apex/facebookPage?code=AQCAmhJfKJ5zSa8pYhI11qNz9L7nLEcVHz6YjiS2VUQfUJbvoIylB8DfI1M7Blwjx0jdVluatTgB_cslPf1m4mLN_PQ6ZMkcHNHpTKkiZxctic6dil_4KYpXgZv91L9cSV4t2KH7a3ZXYr3bJ2zf8U_wWEJ1_kRcdwozF7Y22ET6gH70VlnR87qaEjEEWltraO6MyEbcw7e9ChBQNLHsfJCN579lFXNmqwlhCzSmdQHCQxRWxRUNSdvMi9_jy5CGzD0hOo9MaplIbg0StUx-goGANIBz5sM0cXcyeLhc4ArU-bDL8R18zRB_O0yAmvULEq0vgBcvkG8tXOMU34SISffu&state=NanduKumar#_=_
STEP 10 : Open your controller (FaceBookController)
Replace:
req.setEndpoint('https://graph.facebook.com/oauth/access_token? client_id=0000000000000000
&redirect_uri=https://c.ap1.visual.force.com/apex/facebookPage
&client_secret=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
&code=oxoxoxoxoxoxoxoxoxoxoxoxoxo');
1. client_id : Your facebook App Id
2. redirect_uri : Your visual force page url
3. client_secret : Your App Secret
4 . code : Follow step 9
STEP 11 : Save it and click the button (Click me)
STEP 12 : Open the debug log and copy the acesstoken
STEP 13 : Open developer console (or) work bench
HttpRequest req=new HttpRequest();
req.setMethod('GET');
req.setEndpoint('https://graph.facebook.com/me/feed?
access_token= CAAWXFVyKF0oBAAT6
jw3zU66dZBX3e6W0zZCL07ppLyYJrSRnTb2aMP7eYAPQdtUGpp2sT
PvuX4N4Q9xlx5H2qDwSHCoDhtlTp5Y3aHvGHgZBFYqRWiaOxVQuEFTwlha574l5
8f6KPULGiSORARMPtlQCcgQGjOVd1IValQJNtvZBFf3ew9SLFbPNFVZ
Aj7B9ZCkrCGTxfXCU7xmt1plZCaE');
HttpResponse res = null;
http h= new Http();
res= h.send(req);
system.debug('resp----------'+ res.getbody());
Copy the above code and paste in your developer console or workbench
Replace security token with your security token
Executive
Open the debug log find the resp data
NOTE :
1. The security token is time limit , ones it is expired follow the below STEPS
STEP 1: Go to STEP 8 copy the URL
Replace State = new String (EX: ddhjdhjasdhja)
STEP 2: Follow the STEP 9 , 10 , 11, 12 , 13
2. List of End point URL
To see albums use endpoint urls
https://graph.facebook.com/albums
To see specefied albums's photo
https://graph.facebook.com/albumid/photos
To see posts
https://graph.facebook.com/me/feed
3. To insert photo in to facebook using apex code
HttpRequest req=new HttpRequest();
req.setMethod('POST);
string url ='URL=http://www.visiblebanking.com/wp-content/uploads/
2012/04/Progressive- Flo-FacebookPage-Long-Processed.png';
req.setbody(url);
req.setheader('Content-type', 'application/x-www-form-urlencoded');
req.setHeader('Content-length',string.valueof(url.length()) );
//albumid=000000000000000000
req.setEndpoint('https://graph.facebook.com/000000000000000/photos? access_token=hfsdfhshdfjksdf mdfbsjkf');
HttpResponse res = null;
http h= new Http();
res= h.send(req);
system.debug( 'Resp--------------'+res.getbody());
4 . To comment on photo
HttpRequest req=new HttpRequest();
req.setMethod('POST);
string comment ='message=hai ra mama';
req.setbody(comment);
req.setheader('Content-type', 'application/x-www-form-urlencoded');
req.setHeader('Content-length',string.valueof(sss.length()) );
req.setEndpoint('https://graph.facebook.com/0000000000000/comments?
access_token=hfsdfhshdfjksdf mdfbsjkf');
HttpResponse res = null;
http h= new Http();
res= h.send(req);
system.debug( 'REsp----------------------'+res.getbody());