Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle the "ACAccountCredentialRenewResultRejected" message when calling renewCredentialsForAccount

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?

like image 869
ZachLHelms Avatar asked Jun 20 '13 19:06

ZachLHelms


1 Answers

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.

like image 164
Teddy Avatar answered Nov 13 '22 16:11

Teddy