【发布时间】:2016-02-15 15:31:41
【问题描述】:
我已经用 Objective-C 编写了这段代码
#import <FacebookSDK/FacebookSDK.h>
#import "CustomLoginViewController.h"
#import "AppDelegate.h"
@implementation CustomLoginViewController
- (IBAction)buttonTouched:(id)sender
{
if (FBSession.activeSession.state == FBSessionStateOpen
|| FBSession.activeSession.state == FBSessionStateOpenTokenExtended) {
[FBSession.activeSession closeAndClearTokenInformation];
} else {
[FBSession openActiveSessionWithPublishPermissions:@[@"publish_actions"] defaultAudience:FBSessionDefaultAudienceOnlyMe allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
__block NSString *alertText;
__block NSString *alertTitle;
if (!error) {
if ([FBSession.activeSession.permissions
indexOfObject:@"publish_actions"] == NSNotFound){
// Permission not granted, tell the user we will not publish
alertTitle = @"Permission not granted";
alertText = @"Your action will not be published to Facebook.";
[[[UIAlertView alloc] initWithTitle:alertTitle
message:alertText
delegate:self
cancelButtonTitle:@"OK!"
otherButtonTitles:nil] show];
} else {
// Permission granted, publish the OG story
// [self publishStory];
NSLog(@"Publish permission granted !");
[self publishPOST];
}
} else {
// There was an error, handle it
// See https://developers.facebook.com/docs/ios/errors/
}
// Retrieve the app delegate
AppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
// Call the app delegate's sessionStateChanged:state:error method to handle session state changes
[appDelegate sessionStateChanged:session state:status error:error];
}];
}//else
}
- (IBAction)post:(id)sender {
}
-(void)publishPOST{
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"Description goes here.",@"description",
@"www.google.com/image.jpg",@"picture",
@"www.google.com/invites/username", @"link",
@"Google",@"name",
@"www.google.com",@"caption",
nil];
[FBRequestConnection startWithGraphPath:@"me/feed" parameters:params HTTPMethod:@"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSLog(@"published !");
} else {
NSLog(@"published Failed ??");
}
}];
}
@end
但问题是我想用 FBSessionDefaultAudienceNone 发帖, FBSessionDefaultAudienceOnlyMe、FBSessionDefaultAudienceFriends 和 FBSessionDefaultAudienceEveryone 以编程方式。
我已经写了 FBSessionDefaultAudienceOnlyMe 以仅作为我发布,它对我不起作用。 另一方面,它作为朋友发布。 请任何人帮助我以编程方式仅以我和每个人的身份发布。 如果我错了,请指导我。
提前致谢!
【问题讨论】:
标签: ios objective-c facebook facebook-graph-api