2

I am working on facebook integration using Facebook SDK .. i have uibutton where i am using it to login to facebook and share details on facebook

I am using FBSession to login

 [FBSession.activeSession openWithCompletionHandler:^(FBSession *session, FBSessionState state,NSError *error) {

I am able to login to facebook .. but when i try to share everytime it goes to authorization page even when user has already authorized . i dont want this page to appear other than first time . how to make sure this page doesnt appear everytime user wants to share on facebook

in plist file i have given correct app id and in urlscheme fbappid as well and in my appdelegate i have added handleopenurl , open session

enter image description here

raptor
  • 291
  • 1
  • 9
  • 17
  • I would suggest that the title of question doesn't correspond its content :) The pavan309's answer is good for the *title* meaning – makaron Apr 17 '13 at 16:32

2 Answers2

2

In order to be not asked whether you want to authorize your app or not (despite you're authorized already) you have to reuse you old token. You're making a new one every time, therefore facebook API asks your confirmation.

EDIT :
(suggested by @Slavco Petkovski in comments)

Validate access token you have saved before using it:

if (![FBSDKAccessToken currentAccessToken] ||
      [FBSDKAccessToken currentAccessToken].expirationDate.timeIntervalSince1970 < now.timeIntervalSince1970) {
    // initiate request for a new token
}
makaron
  • 1,585
  • 2
  • 16
  • 30
  • (comment for deleted comment) Not exactly. At the moment when I was responding, we (developers) were better keep access token somewhere (in keychain, database, coredata or whatever) and reuse it each time you want to work with FB. But since each token has an expiration date you had to check first if it was still valid – makaron Nov 03 '15 at 15:07
  • Yes, i edited in question. I do this if (![FBSDKAccessToken currentAccessToken] && ([FBSDKAccessToken currentAccessToken].expirationDate.timeIntervalSince1970 < now.timeIntervalSince1970) ) then get new one – Slavcho Nov 03 '15 at 15:12
  • Well, looks good to me even though it was quite a time since I've worked with FB SDK ) – makaron Nov 03 '15 at 15:15
  • @SlavcoPetkovski In the format the edition was made before I evaluated it as not worth to be added to the answer. If you're 100% sure the code you suggest in comment is working, you may create an edition once again with a code chunk and I'll accept it – makaron Nov 03 '15 at 15:21
0

Its because you have already given permission for this particular app on facebook. Try using a new account you will be asked for permissions.

EDIT

Try using

`+ (BOOL)openActiveSessionWithReadPermissions:(NSArray*)readPermissions
                            allowLoginUI:(BOOL)allowLoginUI
                       completionHandler:(FBSessionStateHandler)handler;`

use the session object that comes in completionHandler

Manan Devani
  • 434
  • 3
  • 15
pavan309
  • 338
  • 1
  • 10
  • new account as in which account ?? and do u have a sample code ? – raptor Apr 17 '13 at 17:47
  • Answer for the title : Any other facebook account which was not authorised previously. If you uses the method which I have given in the answer you dont need to switch to facebook app every time you share – pavan309 Apr 18 '13 at 06:11
  • ..where should i add this method ? ..do u have example where they have used this method ? – raptor Apr 18 '13 at 06:19
  • You can see the example [here](http://stackoverflow.com/questions/12745235/handle-invalid-accesstoken-with-fbsession-openactivesessionwithreadpermissions-i) – pavan309 Apr 18 '13 at 10:08
  • i even tried that it still asking me authorize ...i'll give me project can u help me out if its ok with u – raptor Apr 20 '13 at 03:00
  • Sure, I can give it a try. It will ask you for the very first time if you use it from then it will not. – pavan309 Apr 22 '13 at 01:59
  • this is the link to my project .https://www.dropbox.com/s/hw57rm9axsr47tq/facebookTest%20copy%202.zip – raptor Apr 22 '13 at 08:16
  • It is working fine for me, Only the first time I was asked for the login, I have clicked on cancel. Again I have clicked announce, it didnt navigate me to facebook. Next I have killed the application and then I have rerun the application, even then it didnt navigate me to facebook. – pavan309 Apr 22 '13 at 10:36
  • it didnt ask for authrorization page when the app is opened multiple times ..and btw when i click announce button first time it doesnt show friends ..when i click announce button second time it shows friends list ..why is that ..when i click announce button first time it should show friends list – raptor Apr 22 '13 at 10:38
  • I will look into that after some time and let you know. – pavan309 Apr 22 '13 at 10:40
  • Pavan were u able to look into it – raptor Apr 22 '13 at 14:25
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/28686/discussion-between-pavan309-and-raptor) – pavan309 Apr 22 '13 at 19:39
  • .just one more thing .. when i click announce button first time it navigates to fb to get authorization ..after i click OK ..it doesnt show friends list unless i click the button once again (this happens first time only) – raptor Apr 23 '13 at 15:52