Ответ 1
Пожалуйста, смотрите этот код, это может помочь
postParams=
[@{
@"link" :link,
@"picture" :picture link , //[NSString stringWithFormat:@"%@%@",KBaseImageUrl,@"/assets/img/logo-small.jpg"],
@"name" : @"name",
@"caption" : caption title,
@"description" :discription
} mutableCopy];
title=[[arrayEventInfo valueForKey:@"info"] valueForKey:@"eventname"];
if ([[FBSession activeSession]isOpen])
{
if ([[[FBSession activeSession]permissions]indexOfObject:@"publish_actions"] == NSNotFound)
{
[[FBSession activeSession] requestNewPublishPermissions:[NSArray arrayWithObject:@"publish_action"] defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session,NSError *error){
// If permissions granted, publish the story
[FBRequestConnection
startWithGraphPath:@"me/feed"
parameters:postParams
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
{
NSString *alertText;
if (error)
{
alertText = [NSString stringWithFormat:
@"error: domain = %@, code = %d",
error.domain, error.code];
}
else
{
alertText = @"Posted successfully on your wall.";//[NSString stringWithFormat:
//@"Posted action, id: %@",
// result[@"id"]];
}
//Show the result in an alert
[[[UIAlertView alloc] initWithTitle:title
message:alertText
delegate:self
cancelButtonTitle:@"OK" otherButtonTitles:nil]show];
[FBSession.activeSession closeAndClearTokenInformation];
[FBSession.activeSession close];
}];
UIActivityIndicatorView *activityView=(UIActivityIndicatorView*)[self.view viewWithTag:111];
if(activityView)
{
[activityView removeFromSuperview];
}
[self.view setUserInteractionEnabled:YES];
[self.navigationController.navigationBar setUserInteractionEnabled:YES];
}];
}else
{
// If permissions granted, publish the story
[FBRequestConnection
startWithGraphPath:@"me/feed"
parameters:postParams
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
{
NSString *alertText;
if (error)
{
alertText = [NSString stringWithFormat:
@"error: domain = %@, code = %d",
error.domain, error.code];
}
else
{
alertText = @"Posted successfully on your wall.";//[NSString stringWithFormat:
//@"Posted action, id: %@",
// result[@"id"]];
}
//Show the result in an alert
[[[UIAlertView alloc] initWithTitle:title
message:alertText
delegate:self
cancelButtonTitle:@"OK" otherButtonTitles:nil]show];
[FBSession.activeSession closeAndClearTokenInformation];
[FBSession.activeSession close];
}];
}
}
else
{
[FBSession openActiveSessionWithPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
defaultAudience:FBSessionDefaultAudienceOnlyMe
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
if (!error && status == FBSessionStateOpen) {
if (!error)
{
// If permissions granted, publish the story
[FBRequestConnection
startWithGraphPath:@"me/feed"
parameters:postParams
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
{
NSString *alertText;
if (error)
{
alertText = [NSString stringWithFormat:
@"error: domain = %@, code = %d",
error.domain, error.code];
}
else
{
alertText = @"Posted successfully on your wall.";//[NSString stringWithFormat:
//@"Posted action, id: %@",
// result[@"id"]];
}
//Show the result in an alert
[[[UIAlertView alloc] initWithTitle:title
message:alertText
delegate:self
cancelButtonTitle:@"OK" otherButtonTitles:nil]show];
[FBSession.activeSession closeAndClearTokenInformation];
[FBSession.activeSession close];
}];
}
}else{
NSLog(@"%@",[error description]);
UIActivityIndicatorView *activityView=(UIActivityIndicatorView*)[self.view viewWithTag:111];
if(activityView)
{
[activityView removeFromSuperview];
}
[self.view setUserInteractionEnabled:YES];
[self.navigationController.navigationBar setUserInteractionEnabled:YES];
}
}];
}