New to Integrate Facebook as well as Visualforce and Apex.
Followed Steps :
Developer account in Facebook. created public app with proper settings
Scopes :- email , public_profile ,user_friends (all are defaults).
sent request for code
retrieved code and then again sent request for access token.
sent request to retrieve my profile.
sending request to https://graph.facebook.com/me/feed/ as below
Code:
public static String sharepostownprofile(String post,String token)
{
Map<String,String> params = new Map<String,String>();
params.put('access_token',token);
params.put('message',post);
String endpoint = 'https://graph.facebook.com/me'+'/feed/';
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(endpoint);
req.setTimeOut(120000);
req.setMethod('POST');
req.setBody(convertParamMaptoString(params));
HttpResponse res = h.send(req);
String response = res.getBody();
if(res.getStatusCode() == 302)
{
response = '{"data": [{"url": "'+res.getHeader('Location')+'"},]}';
}
return response ;
}
public static String convertParamMaptoString(Map<String,String> params){
String returned = '';
for(String key : params.keySet()){
if(returned == ''){
//returned += ‘?’;
}
else {
returned += '&';
}
returned += key+'='+EncodingUtil.urlEncode(params.get(key), 'UTF-8');
}
return returned;
}
Getting error:
User hasn't authorised to perform this action.
What scopes are required to share post on my own timeline?