我正在开发一个 iPhone 应用程序,在这个应用程序中,我可以选择与 Facebook 分享我的帖子(我只是传递 facebook 用户的用户 ID,而我的服务器端开发人员负责发布部分)我可以获取用户 ID虽然登录脸书但问题是 - 在用户从 facebook 进行身份验证后,“代表您发布”没有进入应用程序(我正在使用 ios6 SDK)(我已经在 facebook 中创建了我的应用程序并检查了来自图表的 public_action ) 我已经浏览了 facebook 开发者页面中给出的教程(美味),但无法做到
这是我的代码-如果有人发现错误或缺少的部分,请帮我清除
AppDelegate.h
#import <FacebookSDK/FacebookSDK.h>
@class ViewController;
@interface AppDelegate : UIResponder
@property (strong, nonatomic) FBSession *session;
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) ViewController *viewController;
@property (strong,nonatomic) IBOutlet UINavigationController *navBar;
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI;
@end
AppDelegate.m
#import "AppDelegate.h"
#import "ViewController.h"
#define APP_ID @"fd725FDE45a44198a5b8ad3f7a0ffa09"
@implementation AppDelegate
@synthesize session = _session;
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
return [self.session handleOpenURL:url];
}
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
NSArray *permissions = [[NSArray alloc] initWithObjects:
@"user_location",
@"user_birthday",
@"user_likes",
@"email",
@"publish_action",
nil];
return [FBSession openActiveSessionWithPermissions:permissions
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
[self sessionStateChanged:session
state:state error:error];
}];
}
- (void)sessionStateChanged:(FBSession *)session
state:(FBSessionState)state
error:(NSError *)error
{
switch (state) {
case FBSessionStateOpen: {
FBCacheDescriptor *cacheDescriptor = [FBFriendPickerViewController cacheDescriptor];
[cacheDescriptor prefetchAndCacheForSession:session];
}
break;
case FBSessionStateClosed: {
[FBSession.activeSession closeAndClearTokenInformation];
[self performSelector:@selector(showLoginView)
withObject:nil
afterDelay:0.5f];
}
break;
case FBSessionStateClosedLoginFailed: {
[self performSelector:@selector(showLoginView)
withObject:nil
afterDelay:0.5f];
}
break;
default:
break;
}
}
@end
邀请朋友ViewController.h
@interface InviteFriendViewController :
-(IBAction)fbfrnds:(id)sender;
- (void)updateView;
@end
邀请朋友视图控制器.m
- (void)viewDidLoad
{
[super viewDidLoad];
[self.navigationController setNavigationBarHidden:YES];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
userid = [defaults objectForKey:@"userid"];
AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
if (!appDelegate.session.isOpen) {
appDelegate.session = [[FBSession alloc] init];
if (appDelegate.session.state == FBSessionStateCreatedTokenLoaded) {
[appDelegate.session openWithCompletionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
[self updateView];
}
];
}
}
}
-(void)facebookReteriveInformation:(NSDictionary *)dictnry{
FriendlistViewController *friends = [[FriendlistViewController alloc]initWithNibName:@"FriendlistViewController" bundle:nil];
friends.token = string;
[self.navigationController pushViewController:friends animated:YES];
}
-(IBAction)fbfrnds:(id)sender{
sharedClass=[SharedClass sharedInstance];
appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
if (appDelegate.session.isOpen) {
[self updateView];
} else {
if (appDelegate.session.state != FBSessionStateCreated) {
appDelegate.session = [[FBSession alloc] init];
}
[appDelegate.session openWithCompletionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
[self updateView];
}];
}
NSLog(@"string issss %@",string);
}
- (void)updateView {
AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
if (appDelegate.session.isOpen) {
string = [NSString stringWithFormat:@"%@",
appDelegate.session.accessToken];
NSLog(@"string issss %@",string);
NSString *urlstrng;
if(flag == 1){
urlstrng = [NSString stringWithFormat:@"https://graph.facebook.com/me?access_token=%@",
string];
[self dataFetching:urlstrng];
}
} else {
string = [NSString stringWithFormat:@"%@",
appDelegate.session.accessToken];
NSString *urlstrng;
if(flag == 1){
urlstrng = [NSString stringWithFormat:@"https://graph.facebook.com/me?access_token=%@",
string];
[self dataFetching:urlstrng];
}
}
}
-(void)dataFetching:(NSString*)strng1{
NSURL *url = [NSURL URLWithString:strng1];
ProfileConnector *obj = [[ProfileConnector alloc] init];
obj.delegate1 = self;
[obj parsingJson:url];
}
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void) performPublishAction:(void (^)(void)) action {
if ([FBSession.activeSession.permissions indexOfObject:@"publish_actions"] == NSNotFound) {
[FBSession.activeSession reauthorizeWithPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
if (!error) {
action();
}
}];
} else {
action();
}
}
}
@end