ios - iPhone Facebook app: Where does the "permissions array" code go? -
i went through "getting started > mobile apps" documentation on facebook developers. provided code ask permission accessing information don't specify code suppose go.
could tell me put code? because don't want put in wrong space.
the code want add:
nsarray* permissions = [[nsarray arraywithobjects: @"publish_stream", @"offline_access", nil] retain]; [facebook authorize:permissions delegate:self]; my appdelegate code:
#import "iostestappdelegate.h" @implementation iostestappdelegate @synthesize facebook; @synthesize viewcontroller=_viewcontroller; @synthesize window=_window; @synthesize managedobjectcontext=__managedobjectcontext; @synthesize managedobjectmodel=__managedobjectmodel; @synthesize persistentstorecoordinator=__persistentstorecoordinator; - (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions { // override point customization after application launch. [self.window makekeyandvisible]; /* step 2. within body of application:didfinishlaunchingwithoptions: method create instance of facebook class using app id */ facebook = [[facebook alloc] initwithappid:@"********"]; /* step 3. once instance created, check saved access token information. */ nsuserdefaults *defaults = [nsuserdefaults standarduserdefaults]; if ([defaults objectforkey:@"fbaccesstokenkey"] && [defaults objectforkey:@"fbexpirationdatekey"]) { facebook.accesstoken = [defaults objectforkey:@"fbaccesstokenkey"]; facebook.expirationdate = [defaults objectforkey:@"fbexpirationdatekey"]; } /* step 4. check valid session , if not valid call authorize method both signin user , prompt user authorize app: */ if (![facebook issessionvalid]) { [facebook authorize:nil delegate:self]; } return yes; } /* step 5. add application:handleopenurl: method appdelegate call facebook instance: */ - (bool)application:(uiapplication *)application handleopenurl:(nsurl *)url { return [facebook handleopenurl:url]; } /* step 6. implement fbdidlogin method fbsessiondelegate implementation. in method save user's credentials access token , corresponding expiration date. */ - (void)fbdidlogin { nsuserdefaults *defaults = [nsuserdefaults standarduserdefaults]; [defaults setobject:[facebook accesstoken] forkey:@"fbaccesstokenkey"]; [defaults setobject:[facebook expirationdate] forkey:@"fbexpirationdatekey"]; [defaults synchronize]; } ... @end
after allocate facebook instance, have provide these permission authorizing facebook user_credentials. means getting these permission user login.
facebook=[[facebook alloc]initwithappid:kappid]; _permissions = [[nsarray arraywithobjects:@"publish_stream",@"offline_access",nil]retain]; [facebook authorize:_permissions delegate:self]; publish stream provides : enables app post content, comments, , likes user's stream , streams of user's friends. permission, can publish content user's feed @ time, without requiring offline_access. however, please note facebook recommends user-initiated sharing model.
offline access: enables app perform authorized requests on behalf of user @ time. default, access tokens expire after short time period ensure applications make requests on behalf of user when actively using application. permission makes access token returned our oauth endpoint long-lived.
refer more details permission here
Comments
Post a Comment