0

New to Integrate Facebook as well as Visualforce and Apex.

Followed Steps :

  1. Developer account in Facebook. created public app with proper settings

  2. Scopes :- email , public_profile ,user_friends (all are defaults).

  3. sent request for code

  4. retrieved code and then again sent request for access token.

  5. sent request to retrieve my profile.

  6. 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?

1 Answer 1

1

Scopes :- publish_actions and user_posts you can use. For detail Information you can check Documentation of Facebook Graph API.

Scopes for post on facebook page are :- manage_pages,publish_pages

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .