melwyn pawar melwyn pawar - 7 months ago 37
Swift Question

ios swift 2 post on facebook page on behalf of the page

facebook provided the below code to post on to a page, however i am unable to find a swift version of the code also considering facebook has moved to FBSDKGraphRequest v2.6

NSDictionary *params = @{
@"message": @"This is a test message",
};
/* make the API call */
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:@"/{page-id}/feed"
parameters:params
HTTPMethod:@"POST"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error) {
// Handle the result
}];

Answer

This get's the job done

let request = FBSDKGraphRequest(graphPath: "page-id/feed", parameters: ["Message" : "Hello there"], HTTPMethod: "POST")

    request.startWithCompletionHandler { (connection, result, error) in
        //Handle the request
    }

You can setup you params with whatever you want. Read about the params here: FBSDK

Read more here: Facebook

Comments