Facebook在iPhone应用程序
我正在一个iPhone应用程序,在这个我有一个select,分享我的脸书(我只是传递Facebook用户的用户名和我的服务器端开发人员做张贴部分)我可以采取用户ID而在脸书login但问题是,在用户从Facebookauthentication后,“以您的名义”没有进来的应用程序(我使用ios6 SDK)(我创build了我的应用程序在Facebook中检查public_action从图)我已经通过Facebook开发者页面给出的教程(美味),但不能做到
这里是我的代码 – 如果有任何人发现错误或缺less的部分,请帮助我清除
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
InviteFriendViewController.h
@interface InviteFriendViewController : -(IBAction)fbfrnds:(id)sender; - (void)updateView; @end
InviteFriendViewController.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
由于您使用的是Facebook SDK的3.1版本, openActiveSessionWithPermissions:allowLoginUI:completionHandler:
不应该被使用,旧的方法似乎不再有效; 从3.1移植文档 ;
…您将需要删除openActiveSessionWithPermissions的使用:allowLoginUI:completionHandler:并将其replace为openActiveSessionWithReadPermissions:allowLoginUI:completionHandler :(甚至更简单,openActiveSessionWithAllowLoginUI)。
后来,当你的应用程序需要发布回Facebook时,你应该使用reauthorizeWithPublishPermissions:defaultAudience:completionHandler:来寻求额外的权限。
更多详细信息,请参阅移植文档 。
- Facebook Graph API for iOSsearch
- 如何在iOS中使用Facebook SDK检索朋友的生日?
- Facebook SDK Singleton在xcode之前自动login后?
- 我怎样才能得到用户信息使用Facebook的SDK 4.1在iOS?
- 照片对我的朋友不可见,但在我的时间表上
- iOS:连接到Facebook,无需离开应用程序进行授权
- 通过Facebook Graph API获取个人资料图片返回“不支持的URL”
- 如何通过FBconnect或iPhone SDK中的graphicsAPI评论或喜欢facebook中的照片?
- 如何实现FacebookgraphicsAPI的注销function