How to handle the "ACAccountCredentialRenewResultRejected" message when calling renewCredentialsForAccount
Asked Answered
F

1

7

I create an ACAccountStore, get access to the user's facebook account, store the account in an ACAccount object, and am able to retrieve the token from the credentials. But when I try and use this token to retrieve information from Facebook it won't authenticate, and attempting to renew the credentials using renewCredentialsForAccount will just yield a response of ACAccountCredentialRenewResultRejected.

I can't get the permission pop-up to show up again to request permission by any easy means either. The only way I can get it to request permission once more is to either change the permissions I'm asking for in the app, or to delete and re-add my facebook account in settings.

How to I go about getting a valid auth token at this point?

Frymire answered 20/6, 2013 at 19:15 Comment(3)
I can recreate this same error by removing the app from my app settings page on facebook. It would seem that it just needs that permission request pop-up to happen once more to get the user's permission, but it just won't pop-up until i log out/in on my phone.Frymire
It seems though, that when making the renewCredentialsForAccount call that the next time i launch the app and try to log in i am prompted to give permissions to the app. Whereas if I do not make that call I am never prompted to do that.Frymire
Same issue here. Easy to reproduce: 1) grant permission once to the app 2) without quitting the go to FB graph explorer and clear all permissions 3) try renewCredentialsForAccount. Did somebody found a solution for this? FB api has a closeSessionsAndToken (or similar) resolving this issue. But what about social api?Taperecord
T
3

Since there is no accepted answer I try to reply what I found. After my comment above I read the documentation about renewCredentialsForAccount which says "If the user has deauthorized your app, this renewal request will return ACAccountCredentialRenewResultRejected."

What is missleading that it is not the user who rejects but Facebook.

I think I understand the concept now and I try to reply to those who failed with this issue like me. In fact what I did not realise is that my FB token will be completely reset when I receive ACAccountCredentialRenewResultRejected result. And that is the key element in the puzzle.

So what you need to do for different results:

  • ACAccountCredentialRenewResultRenewed you are good to go and you have a new token. Go and perform your SLRequest with this renewed token.
  • ACAccountCredentialRenewResultRejected: your token is reset, if you try to obtain one it will be a nil. You have to request permissions from the users from scratch and "install" the App for Facebook. That means you ask first for the usual "email+other read permissions" and (if you need so) in a separate request you ask for write permissions. (Someone could explain why Facebook wants me to bother the user twice if I want to upload a photo for instance)
  • ACAccountCredentialRenewResultFailed: I could not reproduce this ever. I beleive here you drop an error message to the user.

This is what I came up with. It is a very nasty API which has a poor documentation and missing samples. Also the examples around the Internet are about the "Success" and they do not care about the fact that the user can revoke permissions outside the app. I am in a constant try & fail development mode. Loosing gray hair but coming to the end. I hope my response helps others.

Taperecord answered 21/3, 2015 at 9:18 Comment(1)
very useful and detailed explanation, thumb up!Mandatory

© 2022 - 2024 — McMap. All rights reserved.